mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-23 09:50:27 +08:00
zap
This commit is contained in:
parent
85461165e8
commit
987e6b1004
@ -67,16 +67,16 @@ func NewZapLogger(logLevel int, isStdout bool, isJson bool) (*ZapLogger, error)
|
|||||||
InitialFields: map[string]interface{}{"PID": os.Getegid()},
|
InitialFields: map[string]interface{}{"PID": os.Getegid()},
|
||||||
DisableStacktrace: true,
|
DisableStacktrace: true,
|
||||||
}
|
}
|
||||||
if isJson {
|
// if isJson {
|
||||||
zapConfig.Encoding = "json"
|
// zapConfig.Encoding = "json"
|
||||||
} else {
|
// } else {
|
||||||
zapConfig.Encoding = "console"
|
// zapConfig.Encoding = "console"
|
||||||
}
|
// }
|
||||||
if isStdout {
|
// if isStdout {
|
||||||
zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stdout", "stderr")
|
// zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stdout", "stderr")
|
||||||
}
|
// }
|
||||||
zl := &ZapLogger{}
|
zl := &ZapLogger{}
|
||||||
opts, err := zl.cores(logLevel, isStdout)
|
opts, err := zl.cores(logLevel, isStdout, isJson)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -88,7 +88,7 @@ func NewZapLogger(logLevel int, isStdout bool, isJson bool) (*ZapLogger, error)
|
|||||||
return zl, nil
|
return zl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ZapLogger) cores(logLevel int, isStdout bool) (zap.Option, error) {
|
func (l *ZapLogger) cores(logLevel int, isStdout bool, isJson bool) (zap.Option, error) {
|
||||||
c := zap.NewProductionEncoderConfig()
|
c := zap.NewProductionEncoderConfig()
|
||||||
c.EncodeTime = zapcore.ISO8601TimeEncoder
|
c.EncodeTime = zapcore.ISO8601TimeEncoder
|
||||||
c.EncodeDuration = zapcore.SecondsDurationEncoder
|
c.EncodeDuration = zapcore.SecondsDurationEncoder
|
||||||
@ -97,7 +97,12 @@ func (l *ZapLogger) cores(logLevel int, isStdout bool) (zap.Option, error) {
|
|||||||
c.LevelKey = "level"
|
c.LevelKey = "level"
|
||||||
c.TimeKey = "time"
|
c.TimeKey = "time"
|
||||||
c.CallerKey = "caller"
|
c.CallerKey = "caller"
|
||||||
fileEncoder := zapcore.NewJSONEncoder(c)
|
var fileEncoder zapcore.Encoder
|
||||||
|
if isJson {
|
||||||
|
fileEncoder = zapcore.NewJSONEncoder(c)
|
||||||
|
} else {
|
||||||
|
fileEncoder = zapcore.NewConsoleEncoder(c)
|
||||||
|
}
|
||||||
fileEncoder.AddInt("PID", os.Getpid())
|
fileEncoder.AddInt("PID", os.Getpid())
|
||||||
writer, err := l.getWriter()
|
writer, err := l.getWriter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user