Skip to content

Commit

Permalink
[log] optimize console log format (#3499)
Browse files Browse the repository at this point in the history
  • Loading branch information
huof6829 authored and dustinxie committed Sep 1, 2022
1 parent 222a9dc commit ec7d802
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 130 deletions.
25 changes: 18 additions & 7 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,30 @@ 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, 0644)
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.AddSync(os.Stdout),
cfg.Zap.Level))

core := zapcore.NewTee(cores...)
logger := zap.New(core, opts...)

_logMu.Lock()
if name == _globalLoggerName {
_globalCfg = cfg
Expand Down
26 changes: 0 additions & 26 deletions pkg/log/redirectStderr_armOS.go

This file was deleted.

26 changes: 0 additions & 26 deletions pkg/log/redirectStderr_darwin_arm64.go

This file was deleted.

26 changes: 0 additions & 26 deletions pkg/log/redirectStderr_other.go

This file was deleted.

44 changes: 0 additions & 44 deletions pkg/log/redirectStderr_windows.go

This file was deleted.

2 changes: 1 addition & 1 deletion server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func main() {

func initLogger(cfg config.Config) error {
addr := cfg.Chain.ProducerAddress()
return log.InitLoggers(cfg.Log, cfg.SubLogs, zap.Fields(
return log.InitLoggers(cfg.Log, cfg.SubLogs, zap.AddCaller(), zap.Fields(
zap.String("ioAddr", addr.String()),
))
}

0 comments on commit ec7d802

Please sign in to comment.