rs / zerolog

Zero Allocation JSON Logger
MIT License
10.61k stars 572 forks source link

FilteredLevelWriter writes only logs at Level or above #573

Closed mitar closed 1 year ago

mitar commented 1 year ago

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.

rs commented 1 year ago

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

mitar commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

Done!