(lvl zapcore.Level, msg string)
| 320 | } |
| 321 | |
| 322 | func (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) |
no test coverage detected