mirror of
https://github.com/zrepl/zrepl.git
synced 2025-01-02 20:38:50 +01:00
logger: support replacing fields
do no delete() from array since this could lead to resizing refs #10
This commit is contained in:
parent
f14dc3107f
commit
51377a8ffb
@ -103,12 +103,17 @@ func (l *Logger) WithOutlet(outlet Outlet, level Level) *Logger {
|
|||||||
return child
|
return child
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Logger) ReplaceField(field string, val interface{}) *Logger {
|
||||||
|
l.fields[field] = nil
|
||||||
|
return l.WithField(field, val)
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Logger) WithField(field string, val interface{}) *Logger {
|
func (l *Logger) WithField(field string, val interface{}) *Logger {
|
||||||
|
|
||||||
l.mtx.Lock()
|
l.mtx.Lock()
|
||||||
defer l.mtx.Unlock()
|
defer l.mtx.Unlock()
|
||||||
|
|
||||||
if _, ok := l.fields[field]; ok {
|
if val, ok := l.fields[field]; ok && val != nil {
|
||||||
l.logInternalError(nil,
|
l.logInternalError(nil,
|
||||||
fmt.Sprintf("caller overwrites field '%s'. Stack: %s", field, string(debug.Stack())))
|
fmt.Sprintf("caller overwrites field '%s'. Stack: %s", field, string(debug.Stack())))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user