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

FilteredLevelWriter writes only logs at Level or above #573

Merged
merged 1 commit into from
Aug 2, 2023

Conversation

mitar
Copy link
Contributor

@mitar mitar commented Aug 2, 2023

Fixes #150.

This allows one to combine FilteredLevelWriter, LevelWriterAdapter and MultiLevelWriter into any way you want. E.g., have info and above being logged to the console while all levels to a file.

@mitar mitar changed the title FilteredWriter writes only logs at Level or above FilteredLevelWriter writes only logs at Level or above Aug 2, 2023
@rs
Copy link
Owner

rs commented Aug 2, 2023

The recommended way to do that is to set the level on the logger, so the event is skipped early.

@mitar
Copy link
Contributor Author

mitar commented Aug 2, 2023

The recommended way to do that is to set the level on the logger, so the event is skipped early.

Yes, but this is not possible if you want to log to multiple destinations (e.g., console and file). Then you have to set the level on the logger to the lowest of those you want and then filter at the writer.

@rs
Copy link
Owner

rs commented Aug 2, 2023

Make sense. Can you please add a note on the description of this writer about the use-case it is covering so people don’t think that is the recommended way to deal with levels?

@mitar
Copy link
Contributor Author

mitar commented Aug 2, 2023

Done!

@rs rs merged commit 70ac648 into rs:master Aug 2, 2023
madkins23 pushed a commit to madkins23/zerolog that referenced this pull request Mar 2, 2024
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 this pull request may close these issues.

Multiple writers, different levels on each?
2 participants