diff --git a/log/event.go b/log/event.go index b82deb2e..91a5f550 100644 --- a/log/event.go +++ b/log/event.go @@ -197,9 +197,9 @@ func (e *Event) shouldLog(l Level) bool { } func (e *Event) globalLevelWithOverride() Level { - mu.Lock() + mu.RLock() l, ov := level, overrides - mu.Unlock() + mu.RUnlock() if e.fields == nil { return l } @@ -217,9 +217,9 @@ func (e *Event) globalLevelWithOverride() Level { } func (e *Event) maybeApplyContexters() bool { - mu.Lock() + mu.RLock() hasOverrides := len(overrides) > 0 - mu.Unlock() + mu.RUnlock() if hasOverrides { e.applyContexters() } diff --git a/log/log.go b/log/log.go index f361b317..c4934f05 100644 --- a/log/log.go +++ b/log/log.go @@ -20,7 +20,7 @@ var ( format = DefaultFormat overrides = make(map[string]*levelOverride) output io.Writer = DefaultOutput - mu = &sync.Mutex{} + mu = &sync.RWMutex{} ) // Fatal prints the given message, and exits the program @@ -85,8 +85,8 @@ func Timing(f func()) *Event { // CurrentLevel returns the current log level func CurrentLevel() Level { - mu.Lock() - defer mu.Unlock() + mu.RLock() + defer mu.RUnlock() return level } @@ -111,10 +111,10 @@ func ResetLevelOverrides() { overrides = make(map[string]*levelOverride) } -// CurrentFormat returns the current log formt +// CurrentFormat returns the current log format func CurrentFormat() Format { - mu.Lock() - defer mu.Unlock() + mu.RLock() + defer mu.RUnlock() return format } @@ -138,8 +138,8 @@ func SetOutput(w io.Writer) { // File returns the log file, if any, or an empty string otherwise func File() string { - mu.Lock() - defer mu.Unlock() + mu.RLock() + defer mu.RUnlock() if f, ok := output.(*os.File); ok { return f.Name() } @@ -148,8 +148,8 @@ func File() string { // IsFile returns true if the output is a non-default file func IsFile() bool { - mu.Lock() - defer mu.Unlock() + mu.RLock() + defer mu.RUnlock() if _, ok := output.(*os.File); ok && output != DefaultOutput { return true }