Jeff saves the day
This commit is contained in:
parent
dc77efc31a
commit
057c4a3239
2 changed files with 14 additions and 14 deletions
|
@ -197,9 +197,9 @@ func (e *Event) shouldLog(l Level) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Event) globalLevelWithOverride() Level {
|
func (e *Event) globalLevelWithOverride() Level {
|
||||||
mu.Lock()
|
mu.RLock()
|
||||||
l, ov := level, overrides
|
l, ov := level, overrides
|
||||||
mu.Unlock()
|
mu.RUnlock()
|
||||||
if e.fields == nil {
|
if e.fields == nil {
|
||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
@ -217,9 +217,9 @@ func (e *Event) globalLevelWithOverride() Level {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Event) maybeApplyContexters() bool {
|
func (e *Event) maybeApplyContexters() bool {
|
||||||
mu.Lock()
|
mu.RLock()
|
||||||
hasOverrides := len(overrides) > 0
|
hasOverrides := len(overrides) > 0
|
||||||
mu.Unlock()
|
mu.RUnlock()
|
||||||
if hasOverrides {
|
if hasOverrides {
|
||||||
e.applyContexters()
|
e.applyContexters()
|
||||||
}
|
}
|
||||||
|
|
20
log/log.go
20
log/log.go
|
@ -20,7 +20,7 @@ var (
|
||||||
format = DefaultFormat
|
format = DefaultFormat
|
||||||
overrides = make(map[string]*levelOverride)
|
overrides = make(map[string]*levelOverride)
|
||||||
output io.Writer = DefaultOutput
|
output io.Writer = DefaultOutput
|
||||||
mu = &sync.Mutex{}
|
mu = &sync.RWMutex{}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Fatal prints the given message, and exits the program
|
// Fatal prints the given message, and exits the program
|
||||||
|
@ -85,8 +85,8 @@ func Timing(f func()) *Event {
|
||||||
|
|
||||||
// CurrentLevel returns the current log level
|
// CurrentLevel returns the current log level
|
||||||
func CurrentLevel() Level {
|
func CurrentLevel() Level {
|
||||||
mu.Lock()
|
mu.RLock()
|
||||||
defer mu.Unlock()
|
defer mu.RUnlock()
|
||||||
return level
|
return level
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,10 +111,10 @@ func ResetLevelOverrides() {
|
||||||
overrides = make(map[string]*levelOverride)
|
overrides = make(map[string]*levelOverride)
|
||||||
}
|
}
|
||||||
|
|
||||||
// CurrentFormat returns the current log formt
|
// CurrentFormat returns the current log format
|
||||||
func CurrentFormat() Format {
|
func CurrentFormat() Format {
|
||||||
mu.Lock()
|
mu.RLock()
|
||||||
defer mu.Unlock()
|
defer mu.RUnlock()
|
||||||
return format
|
return format
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,8 +138,8 @@ func SetOutput(w io.Writer) {
|
||||||
|
|
||||||
// File returns the log file, if any, or an empty string otherwise
|
// File returns the log file, if any, or an empty string otherwise
|
||||||
func File() string {
|
func File() string {
|
||||||
mu.Lock()
|
mu.RLock()
|
||||||
defer mu.Unlock()
|
defer mu.RUnlock()
|
||||||
if f, ok := output.(*os.File); ok {
|
if f, ok := output.(*os.File); ok {
|
||||||
return f.Name()
|
return f.Name()
|
||||||
}
|
}
|
||||||
|
@ -148,8 +148,8 @@ func File() string {
|
||||||
|
|
||||||
// IsFile returns true if the output is a non-default file
|
// IsFile returns true if the output is a non-default file
|
||||||
func IsFile() bool {
|
func IsFile() bool {
|
||||||
mu.Lock()
|
mu.RLock()
|
||||||
defer mu.Unlock()
|
defer mu.RUnlock()
|
||||||
if _, ok := output.(*os.File); ok && output != DefaultOutput {
|
if _, ok := output.(*os.File); ok && output != DefaultOutput {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue