MCPcopy
hub / github.com/rs/zerolog / UpdateContext

Method UpdateContext

log.go:296–308  ·  view source on GitHub ↗

UpdateContext updates the internal logger's context. Caution: This method is not concurrency safe. Use the With method to create a child logger before modifying the context from concurrent goroutines.

(update func(c Context) Context)

Source from the content-addressed store, hash-verified

294// Caution: This method is not concurrency safe.
295// Use the With method to create a child logger before modifying the context from concurrent goroutines.
296func (l *Logger) UpdateContext(update func(c Context) Context) {
297 if l.disabled() {
298 return
299 }
300 if cap(l.context) == 0 {
301 l.context = make([]byte, 0, 500)
302 }
303 if len(l.context) == 0 {
304 l.context = enc.AppendBeginMarker(l.context)
305 }
306 c := update(Context{*l})
307 l.context = c.l.context
308}
309
310// Level creates a child logger with the minimum accepted level set to level.
311func (l Logger) Level(lvl Level) Logger {

Callers 15

TestUpdateEmptyContextFunction · 0.80
TestCtxDisabledFunction · 0.80
URLHandlerFunction · 0.80
MethodHandlerFunction · 0.80
RequestHandlerFunction · 0.80
RemoteAddrHandlerFunction · 0.80
RemoteIPHandlerFunction · 0.80
UserAgentHandlerFunction · 0.80
RefererHandlerFunction · 0.80

Calls 2

disabledMethod · 0.95
AppendBeginMarkerMethod · 0.65

Tested by 6

TestUpdateEmptyContextFunction · 0.64
TestCtxDisabledFunction · 0.64
BenchmarkDataRaceFunction · 0.64