Skip to content

Commit

Permalink
*: fix log format (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Nov 2, 2022
1 parent 4f31e77 commit b8de341
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/util/cmd/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@
package cmd

import (
"time"

"github.com/pingcap/TiProxy/lib/config"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func buildEncoder(cfg *config.Log) (zapcore.Encoder, error) {
encfg := zap.NewProductionEncoderConfig()
encfg.EncodeTime = func(t time.Time, pae zapcore.PrimitiveArrayEncoder) {
pae.AppendString(t.Format("2006/01/02 15:04:05.000 -07:00"))
}
encfg.EncodeLevel = func(l zapcore.Level, pae zapcore.PrimitiveArrayEncoder) {
pae.AppendString(l.CapitalString())
}
switch cfg.Encoder {
case "json":
return zapcore.NewJSONEncoder(encfg), nil
Expand Down Expand Up @@ -57,5 +65,5 @@ func BuildLogger(cfg *config.Log) (*zap.Logger, *AtomicWriteSyncer, zap.AtomicLe
if err != nil {
return nil, nil, level, err
}
return zap.New(zapcore.NewCore(encoder, syncer, level), zap.ErrorOutput(syncer), zap.AddStacktrace(zapcore.FatalLevel)), syncer, level, nil
return zap.New(zapcore.NewCore(encoder, syncer, level), zap.ErrorOutput(syncer), zap.AddStacktrace(zapcore.FatalLevel), zap.AddCaller()), syncer, level, nil
}

0 comments on commit b8de341

Please sign in to comment.