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

Incorrect work with the log level option #21

Closed
mdigger opened this issue May 13, 2023 · 0 comments
Closed

Incorrect work with the log level option #21

mdigger opened this issue May 13, 2023 · 0 comments

Comments

@mdigger
Copy link

mdigger commented May 13, 2023

During initialization in the tint.NewHandler, the minimum logging level is copied as a number and then used as an absolute value that cannot be changed.

And in the settings, not just the minimum level is set, but the slog.Leveler interface, which allows you to safely change this value in the future.

var programLevel = new(slog.LevelVar) // Info by default
h := tint.NewHandler(os.Stderr, &tint.HandlerOptions{
    Level: programLevel,
})
slog.SetDefault(slog.New(h))
// ...
programLevel.Set(slog.LevelDebug) // <- DON'T WORK!!!

FYI: https://pkg.go.dev/golang.org/x/exp/slog#hdr-Levels

Accordingly, in the internal handler you also need to replace level slog.Level with slog.Leveler and:

func (h *handler) Enabled(_ context.Context, level slog.Level) bool {
    return level >= h.level.Level()
}
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

No branches or pull requests

1 participant