-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
DefaultLogger.WithCaller() is broken with slog #599
Comments
You most likely will have to set the caller offset as well. WithCaller().WithCallerOffset(4) |
As @ccremer said, you would need to set an offset here. For your specific example, an offset of 3 works: pterm.DefaultLogger.WithCaller().Info("default logger")
logger := slog.New(pterm.NewSlogHandler(pterm.DefaultLogger.WithCaller().WithCallerOffset(3)))
logger.Info("slog logger") We could try to guess the offset, if I will definitely document this on the |
Thanks everybody for your quick response. |
@MarvinJWendt If we are talking breaking changes, maybe |
@ccremer the offset is only required if the logger := pterm.DefaultLogger.WithCaller()
logger.Info("some info") Works as expected. We could inject more offset in We could also implement that as a non-breaking change, and only add an offset in |
Right, I haven't thought of that ;) Overall I'm happy with your proposal. An 80/20 approach to reduce boilerplate is probably still better than no approach. |
Description
The
WithCaller()
option of the pterm logger is broken when used withpterm.NewSlogHandler
and always returns/slog_handler.go:55
as the callerHow to reproduce
expected result
actual result
Impacted version
Tested with pterm
v0.12.72
and Go1.21.5
The text was updated successfully, but these errors were encountered: