mirror of
https://github.com/zrepl/zrepl.git
synced 2025-01-03 04:48:55 +01:00
logger: fix ReplaceWith: would case parent field to be nil
Now WithField and ReplaceWith are wrappers around a common
forkLogger routine
regression introduced in 51377a8
This commit is contained in:
parent
6b5bd0a43c
commit
fc1c46ffd7
@ -92,20 +92,8 @@ func (l *Logger) WithOutlet(outlet Outlet, level Level) *Logger {
|
|||||||
return child
|
return child
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) ReplaceField(field string, val interface{}) *Logger {
|
// callers must hold l.mtx
|
||||||
l.fields[field] = nil
|
func (l *Logger) forkLogger(field string, val interface{}) *Logger {
|
||||||
return l.WithField(field, val)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Logger) WithField(field string, val interface{}) *Logger {
|
|
||||||
|
|
||||||
l.mtx.Lock()
|
|
||||||
defer l.mtx.Unlock()
|
|
||||||
|
|
||||||
if val, ok := l.fields[field]; ok && val != nil {
|
|
||||||
l.logInternalError(nil,
|
|
||||||
fmt.Sprintf("caller overwrites field '%s'. Stack: %s", field, string(debug.Stack())))
|
|
||||||
}
|
|
||||||
|
|
||||||
child := &Logger{
|
child := &Logger{
|
||||||
fields: make(Fields, len(l.fields)+1),
|
fields: make(Fields, len(l.fields)+1),
|
||||||
@ -119,7 +107,22 @@ func (l *Logger) WithField(field string, val interface{}) *Logger {
|
|||||||
child.fields[field] = val
|
child.fields[field] = val
|
||||||
|
|
||||||
return child
|
return child
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Logger) ReplaceField(field string, val interface{}) *Logger {
|
||||||
|
l.mtx.Lock()
|
||||||
|
defer l.mtx.Unlock()
|
||||||
|
return l.forkLogger(field, val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *Logger) WithField(field string, val interface{}) *Logger {
|
||||||
|
l.mtx.Lock()
|
||||||
|
defer l.mtx.Unlock()
|
||||||
|
if val, ok := l.fields[field]; ok && val != nil {
|
||||||
|
l.logInternalError(nil,
|
||||||
|
fmt.Sprintf("caller overwrites field '%s'. Stack: %s", field, string(debug.Stack())))
|
||||||
|
}
|
||||||
|
return l.forkLogger(field, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Logger) WithFields(fields Fields) (ret *Logger) {
|
func (l *Logger) WithFields(fields Fields) (ret *Logger) {
|
||||||
|
Loading…
Reference in New Issue
Block a user