Skip to content

Commit

Permalink
slog: Ignore frames with a zero PC
Browse files Browse the repository at this point in the history
  • Loading branch information
mway committed Mar 20, 2023
1 parent 05c4b6c commit c992c37
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions exp/zapslog/slog.go
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 c992c37

Please sign in to comment.