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

Pass PC to caller marshaller to allow more detailed information #456

Closed
Hades32 opened this issue Jul 27, 2022 · 3 comments · Fixed by #457
Closed

Pass PC to caller marshaller to allow more detailed information #456

Hades32 opened this issue Jul 27, 2022 · 3 comments · Fixed by #457

Comments

@Hades32
Copy link
Contributor

Hades32 commented Jul 27, 2022

Here the program counter var is _ ignored:

zerolog/event.go

Lines 743 to 753 in 4099072

func (e *Event) caller(skip int) *Event {
if e == nil {
return e
}
_, file, line, ok := runtime.Caller(skip + e.skipFrame)
if !ok {
return e
}
e.buf = enc.AppendString(enc.AppendKey(e.buf, CallerFieldName), CallerMarshalFunc(file, line))
return e
}

If it was passed into the marshaller, we could also print the method name, which we're currently missing.

As this would be a backwards-incompatible change, I'm creating this issue first before creating a PR, but I think it would be worth it and very easy to fix (for the few people that actually overwrite that method manually)

Edit:
This is how you could get the func name:

.Str("func", runtime.FuncForPC(pc).Name())
@Hades32
Copy link
Contributor Author

Hades32 commented Jul 29, 2022

@rs should I create a PR or do you think breaking compatibility (a tiny bit) is a no-go?

@rs
Copy link
Owner

rs commented Jul 29, 2022

Sure go ahead

@Hades32
Copy link
Contributor Author

Hades32 commented Jul 29, 2022

Great, done @rs

@rs rs closed this as completed in #457 Jul 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants