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

proposal: log/slog: implement a method to change logger level #62473

Closed
tiaguinho opened this issue Sep 6, 2023 · 2 comments
Closed

proposal: log/slog: implement a method to change logger level #62473

tiaguinho opened this issue Sep 6, 2023 · 2 comments
Labels
Milestone

Comments

@tiaguinho
Copy link

Today, the only way to change the logger level is creating a new logger.
But there are at least two scenarios where having a method to change the logger level will be nice.

  1. Let's say I have an environment variable to enable DEBUG mode. Instead of create a new logger with the debug level configured, will be easiest just call a method.
logger.SetLevel(slog.LevelDebug)
  1. If I'm using a default logger on my application, and want to enable debug level on a single package.
logger = slog.Default().WithLevel(slog.LevelDebug)

To solve the problem of create a new logger every time the logger level needs to be changed, I'm proposing the implementation of two methods SetLevel and WithLevel.

@gopherbot gopherbot added this to the Proposal milestone Sep 6, 2023
@seankhliao
Copy link
Member

log level filtering/output is a property of the handler, not the logger

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Sep 6, 2023
@tiaguinho
Copy link
Author

Yes @seankhliao, but the handler isn't exposed, so the Logger needs to change the level on the handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants