-
Notifications
You must be signed in to change notification settings - Fork 324
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] optimize console log format #3499
Changes from 16 commits
78f3907
4123be7
42ac755
4fb0253
db60e19
1b10c96
067e215
25bbb17
7c31a2d
b74a988
40ad738
e842ecb
69547b8
9b4de4d
29f77f2
bb722d0
0572272
60f3e47
128e826
ce2faee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,19 +85,38 @@ func InitLoggers(globalCfg GlobalConfig, subCfgs map[string]GlobalConfig, opts . | |
if globalCfg.EcsIntegration { | ||
cfg.Zap.EncoderConfig = ecszap.ECSCompatibleEncoderConfig(cfg.Zap.EncoderConfig) | ||
} | ||
logger, err := cfg.Zap.Build(opts...) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var cores []zapcore.Core | ||
if cfg.StderrRedirectFile != nil { | ||
stderrF, err := os.OpenFile(*cfg.StderrRedirectFile, os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0600) | ||
if err != nil { | ||
return err | ||
} | ||
if err := redirectStderr(stderrF); err != nil { | ||
return err | ||
} | ||
|
||
cores = append(cores, zapcore.NewCore( | ||
zapcore.NewJSONEncoder(cfg.Zap.EncoderConfig), | ||
zapcore.AddSync(stderrF), | ||
cfg.Zap.Level)) | ||
} | ||
|
||
consoleCfg := zap.NewDevelopmentConfig() | ||
consoleCfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder | ||
cores = append(cores, zapcore.NewCore( | ||
zapcore.NewConsoleEncoder(consoleCfg.EncoderConfig), | ||
zapcore.Lock(os.Stderr), | ||
zap.InfoLevel)) | ||
|
||
coreOpt := zap.WrapCore(func(zapcore.Core) zapcore.Core { | ||
return zapcore.NewTee(cores...) | ||
}) | ||
var buildOpts []zap.Option | ||
buildOpts = append(buildOpts, coreOpt) | ||
buildOpts = append(buildOpts, opts...) | ||
logger, err := cfg.Zap.Build(buildOpts...) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no. build error because type of |
||
if err != nil { | ||
return err | ||
} | ||
|
||
_logMu.Lock() | ||
if name == _globalLoggerName { | ||
_globalCfg = cfg | ||
|
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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.
so looks like add a new console encoder to process the output in human-friendly format?
i assume you already run locally to verify the log format in the file has remained the same?
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.
yes, add console encoder. I run in test-net, log format is the same with older