-
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
feat(zap): add multiple zapcore support #19
Conversation
666fa90
to
2fc1a10
Compare
logger := hertzzap.NewLogger(hertzzap.WithZapOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(os.Stdout), zap.NewAtomicLevelAt(zap.ErrorLevel))
}))) maybe we could use zap.WrapCore custom our zapcore? |
|
l, err := os.OpenFile("log.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0755)
if err != nil {
log.Fatal(err)
}
logger := hertzzap.NewLogger(hertzzap.WithZapOptions(zap.WrapCore(func(core zapcore.Core) zapcore.Core {
return zapcore.NewTee([]zapcore.Core{
zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(l), zap.NewAtomicLevelAt(zap.InfoLevel)),
zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(os.Stdout), zap.NewAtomicLevelAt(zap.InfoLevel)),
}...)
}))) multiple zapcore by NewTee |
it indeed a good way to use multiple zapcores in this way |
We can mention this in our documentation, the code change is not necessary for this repository |
WrapCore will take effect finally, and will cause setOutput and setLevel not to work |
In this case, to solve the warped |
It will look weird, and it's not so easy to change the wrapCore behavior, maybe we should avoid using these two func when using wrapCore |
... how's weeird? |
Why just change the first... |
As It can't specify the certain |
sounds ok |
Do you join our lark community group or wechat group. contact me. |
你飞书名字是啥 |
rogerogers |
ce966fa
to
83e6fbf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What type of PR is this?
feat
What this PR does / why we need it (English/Chinese):
目前
hlog
的zap
扩展不支持使用多个zapcore
的场景,比如我既需要输出到控制台,又需要输出到日志文件Which issue(s) this PR fixes: