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

change log level dynamically #252

Open
itapai opened this issue Jul 22, 2020 · 7 comments
Open

change log level dynamically #252

itapai opened this issue Jul 22, 2020 · 7 comments

Comments

@itapai
Copy link

itapai commented Jul 22, 2020

Basically, title.

I want to be able to dynamically set the log level at runtime. Is this achievable with zerolog?
This can be done with zap. https://dev.to/procyclinsur/golang-dynamic-logging-3p7k

@panlatent
Copy link

panlatent commented Aug 14, 2020

I need this feature because zero-log is used as the underlying library.

zero-log assumes people will set the level first.

@mpalmer
Copy link

mpalmer commented Oct 12, 2020

I've achieved this in a HTTP service by setting the log level in the logger that is created for each request (which also carries all the per-request metadata like request ID). This wouldn't work if you need to change log level mid-request, but I'm yet to find that a problem for a typical HTTP service, which deals with short-lived individual requests.

@aldas
Copy link

aldas commented Oct 25, 2020

For us would be use case - our application has API and background processes or shared services that log. During application start logger is created as very first thing. during application startup application configuration is also read in and it could/should be able to change log level.

@rs
Copy link
Owner

rs commented Oct 26, 2020

Store the logger as a pointer with proper locking and change the logger as you please.

@SEJeff
Copy link

SEJeff commented Jan 17, 2023

In go.uber.org/zap this is handled with AtomicLevel. The design of this is sensible and should be considered for zerolog.

@mitar
Copy link
Contributor

mitar commented Aug 20, 2023

I have made #583 to suggest that zerolog needs a batching post-processing capability for (possibly a batch of) log events before they are written out. This would allow one to decide the log level after observing what other log events have been generated for example during request handling. You could then log at debug log level but write the log line only if any of the log lines for the request was an error, or something like that.

@avishaybp81
Copy link

What is wrong with calling SetGlobalLevel
See https://goplay.tools/snippet/Qzy6O7eJEIW

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

8 participants