Skip to content

Commit

Permalink
slog: Ignore frames with a zero PC (#1258)
Browse files Browse the repository at this point in the history
  • Loading branch information
mway authored Mar 20, 2023
1 parent 05c4b6c commit 42b7ef0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions exp/zapslog/slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,16 @@ func (h *Handler) Handle(ctx context.Context, record slog.Record) error {
return nil
}

if h.addSource {
if h.addSource && record.PC != 0 {
frame, _ := runtime.CallersFrames([]uintptr{record.PC}).Next()
ce.Caller = zapcore.EntryCaller{
Defined: true,
PC: frame.PC,
File: frame.File,
Line: frame.Line,
Function: frame.Function,
if frame.PC != 0 {
ce.Caller = zapcore.EntryCaller{
Defined: true,
PC: frame.PC,
File: frame.File,
Line: frame.Line,
Function: frame.Function,
}
}
}

Expand Down

0 comments on commit 42b7ef0

Please sign in to comment.