ethlog: fix StdLogSystem data race on level
This commit is contained in:
parent
d5a7ba1626
commit
45d1052229
@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogSystem interface {
|
type LogSystem interface {
|
||||||
@ -198,7 +199,7 @@ func (logger *Logger) Fatalf(format string, v ...interface{}) {
|
|||||||
|
|
||||||
type StdLogSystem struct {
|
type StdLogSystem struct {
|
||||||
logger *log.Logger
|
logger *log.Logger
|
||||||
level LogLevel
|
level uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *StdLogSystem) Println(v ...interface{}) {
|
func (t *StdLogSystem) Println(v ...interface{}) {
|
||||||
@ -210,14 +211,14 @@ func (t *StdLogSystem) Printf(format string, v ...interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *StdLogSystem) SetLogLevel(i LogLevel) {
|
func (t *StdLogSystem) SetLogLevel(i LogLevel) {
|
||||||
t.level = i
|
atomic.StoreUint32(&t.level, uint32(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *StdLogSystem) GetLogLevel() LogLevel {
|
func (t *StdLogSystem) GetLogLevel() LogLevel {
|
||||||
return t.level
|
return LogLevel(atomic.LoadUint32(&t.level))
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStdLogSystem(writer io.Writer, flags int, level LogLevel) *StdLogSystem {
|
func NewStdLogSystem(writer io.Writer, flags int, level LogLevel) *StdLogSystem {
|
||||||
logger := log.New(writer, "", flags)
|
logger := log.New(writer, "", flags)
|
||||||
return &StdLogSystem{logger, level}
|
return &StdLogSystem{logger, uint32(level)}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user