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

Log different levels to different files like in "glog" #718

Closed
sourabhxyz opened this issue May 29, 2019 · 1 comment
Closed

Log different levels to different files like in "glog" #718

sourabhxyz opened this issue May 29, 2019 · 1 comment

Comments

@sourabhxyz
Copy link

Like glog logs to three different files, viz., name.INFO, name.WARNING, name.ERROR (where INFO also contains logs of higher priority (Warn and Error) as well, similarly for .WARNING and .ERROR), is it possible to do the same with zap? I now I can achieve the same behaviour by running three different loggers each set with their own atomic level but just asking if there is some straight forward way.

@prashantv
Copy link
Collaborator

You can implement a custom zapcore.Core that will multiplex writes to different log levels to different files. A "core" is a backend, and can represent a single file.

As an example, you may want to look at zapcore.NewTee which will log everything to multiple cores. Instead of duplicating the write to all cores, you should check the level of the entry, and determine the appropriate core to write to.

This is not something we plan to provide in zap.

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

No branches or pull requests

2 participants