Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zapslog: Apply callerSkip when addCaller #1380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

2 participants