-
Notifications
You must be signed in to change notification settings - Fork 17
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
In multiple zapcore examples, how do I use the LevelEnablerFunc filter to make the debug file log only the Debug level and the Info file record only the INFO level log #26
Comments
Just following the readme instructions. |
My code follows the demo completely and adds hlog.SetLogger, but the info.log file contains both info and error level logs. I hope info.log only contains logs of info level, and debug.log only contains logs of debug level. |
Here we use AtomicLevel to implement the SetLevel method of hlog. If you don't need the SetLevel method, you can use logger like this. logger := hertzzap.NewLogger(
hertzzap.WithZapOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return zapcore.NewTee(
zapcore.NewCore(
zapcore.NewJSONEncoder(humanEncoderConfig()), getWriteSyncer("log/debug.log"), zap.LevelEnablerFunc(func(level zapcore.Level) bool {
return level == zap.DebugLevel
}),
),
zapcore.NewCore(
zapcore.NewJSONEncoder(humanEncoderConfig()), getWriteSyncer("log/info.log"), zap.LevelEnablerFunc(func(level zapcore.Level) bool {
return level == zap.InfoLevel
}),
),
zapcore.NewCore(
zapcore.NewJSONEncoder(humanEncoderConfig()), getWriteSyncer("log/warn.log"), zap.LevelEnablerFunc(func(level zapcore.Level) bool {
return level == zap.WarnLevel
}),
),
)
}),
),
)
defer logger.Sync()
hlog.SetLogger(logger) |
thanks, It works |
The new version fixed this issue, and you can also refer to the latest version readme for usage instructions. |
In multiple zapcore examples, how do I use the LevelEnablerFunc filter to make the Info file record only the INFO level log,and also, other files also correspond to the level
The text was updated successfully, but these errors were encountered: