MCPcopy
hub / github.com/uber-go/zap / check

Method check

logger.go:322–422  ·  logger.go::Logger.check
(lvl zapcore.Level, msg string)

Source from the content-addressed store, hash-verified

320}
321
322func (log *Logger) check(lvl zapcore.Level, msg string) *zapcore.CheckedEntry {
323 // Logger.check must always be called directly by a method in the
324 // Logger interface (e.g., Check, Info, Fatal).
325 // This skips Logger.check and the Info/Fatal/Check/etc. method that
326 // called it.
327 const callerSkipOffset = 2
328
329 // Check the level first to reduce the cost of disabled log calls.
330 // Since Panic and higher may exit, we skip the optimization for those levels.
331 if lvl < zapcore.DPanicLevel && !log.core.Enabled(lvl) {
332 return nil
333 }
334
335 // Create basic checked entry thru the core; this will be non-nil if the
336 // log message will actually be written somewhere.
337 ent := zapcore.Entry{
338 LoggerName: log.name,
339 Time: log.clock.Now(),
340 Level: lvl,
341 Message: msg,
342 }
343 ce := log.core.Check(ent, nil)
344 willWrite := ce != nil
345
346 // Set up any required terminal behavior.
347 switch ent.Level {
348 case zapcore.PanicLevel:
349 ce = ce.After(ent, terminalHookOverride(zapcore.WriteThenPanic, log.onPanic))
350 case zapcore.FatalLevel:
351 ce = ce.After(ent, terminalHookOverride(zapcore.WriteThenFatal, log.onFatal))
352 case zapcore.DPanicLevel:
353 if log.development {
354 ce = ce.After(ent, terminalHookOverride(zapcore.WriteThenPanic, log.onPanic))
355 }
356 }
357
358 // Only do further annotation if we're going to write this message; checked
359 // entries that exist only for terminal behavior don't benefit from
360 // annotation.
361 if !willWrite {
362 return ce
363 }
364
365 // Thread the error output through to the CheckedEntry.
366 ce.ErrorOutput = log.errorOutput
367
368 addStack := log.addStack.Enabled(ce.Level)
369 if !log.addCaller && !addStack {
370 return ce
371 }
372
373 // Adding the caller or stack trace requires capturing the callers of
374 // this function. We'll share information between these two.
375 stackDepth := stacktrace.First
376 if addStack {
377 stackDepth = stacktrace.Full
378 }
379 stack := stacktrace.Capture(log.callerSkip+callerSkipOffset, stackDepth)

Callers 9

CheckMethod · 0.95
LogMethod · 0.95
DebugMethod · 0.95
InfoMethod · 0.95
WarnMethod · 0.95
ErrorMethod · 0.95
DPanicMethod · 0.95
PanicMethod · 0.95
FatalMethod · 0.95

Calls 15

FormatFrameMethod · 0.95
FormatStackMethod · 0.95
CaptureFunction · 0.92
NewFormatterFunction · 0.92
terminalHookOverrideFunction · 0.85
AfterMethod · 0.80
CountMethod · 0.80
NextMethod · 0.80
EnabledMethod · 0.65
NowMethod · 0.65
CheckMethod · 0.65
SyncMethod · 0.65

Tested by

no test coverage detected