Skip to content

Commit

Permalink
simple set zap.core
Browse files Browse the repository at this point in the history
  • Loading branch information
huof6829 committed Aug 31, 2022
1 parent 128e826 commit ce2faee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
18 changes: 5 additions & 13 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,19 +103,11 @@ func InitLoggers(globalCfg GlobalConfig, subCfgs map[string]GlobalConfig, opts .
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...)
if err != nil {
return err
}
zapcore.AddSync(os.Stdout),
cfg.Zap.Level))

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

_logMu.Lock()
if name == _globalLoggerName {
Expand Down
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 ce2faee

Please sign in to comment.