Skip to content

Conversation

@sjones4
Copy link

@sjones4 sjones4 commented Nov 3, 2023

CallerSkip was added to the Handler but only used for the stacktrace, it should also be applied to the caller with an appropriate offset.

Currently the stacktrace can be correct for a wrapped logger but there is no way to fix the caller information.

Here is the equivalent logger functionality where the skip is applied for the caller:

zap/logger.go

Lines 393 to 414 in c17272e

stack := stacktrace.Capture(log.callerSkip+callerSkipOffset, stackDepth)
defer stack.Free()
if stack.Count() == 0 {
if log.addCaller {
fmt.Fprintf(log.errorOutput, "%v Logger.check error: failed to get caller\n", ent.Time.UTC())
_ = log.errorOutput.Sync()
}
return ce
}
frame, more := stack.Next()
if log.addCaller {
ce.Caller = zapcore.EntryCaller{
Defined: frame.PC != 0,
PC: frame.PC,
File: frame.File,
Line: frame.Line,
Function: frame.Function,
}
}

@CLAassistant
Copy link

CLAassistant commented Nov 3, 2023

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants