mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-02 07:54:19 +08:00
zap
This commit is contained in:
parent
085fc7adbf
commit
15f6626282
@ -2,6 +2,7 @@ package log
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
@ -68,6 +69,8 @@ func NewZapLogger(logLevel int, isStdout bool, isJson bool) (*ZapLogger, error)
|
|||||||
}
|
}
|
||||||
if isJson {
|
if isJson {
|
||||||
zapConfig.Encoding = "json"
|
zapConfig.Encoding = "json"
|
||||||
|
} else {
|
||||||
|
zapConfig.Encoding = "console"
|
||||||
}
|
}
|
||||||
if isStdout {
|
if isStdout {
|
||||||
zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stdout", "stderr")
|
zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stdout", "stderr")
|
||||||
@ -101,11 +104,14 @@ func (l *ZapLogger) cores(logLevel int, isStdout bool) (zap.Option, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var cores []zapcore.Core
|
var cores []zapcore.Core
|
||||||
if config.Config.Log.StorageLocation != "" {
|
if config.Config.Log.StorageLocation != "" && !isStdout {
|
||||||
cores = []zapcore.Core{
|
cores = []zapcore.Core{
|
||||||
zapcore.NewCore(fileEncoder, writer, zap.NewAtomicLevelAt(logLevelMap[logLevel])),
|
zapcore.NewCore(fileEncoder, writer, zap.NewAtomicLevelAt(logLevelMap[logLevel])),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if config.Config.Log.StorageLocation == "" && !isStdout {
|
||||||
|
return nil, errors.New("log storage location is empty and not stdout")
|
||||||
|
}
|
||||||
if isStdout {
|
if isStdout {
|
||||||
cores = append(cores, zapcore.NewCore(fileEncoder, zapcore.Lock(os.Stdout), zap.NewAtomicLevelAt(logLevelMap[logLevel])))
|
cores = append(cores, zapcore.NewCore(fileEncoder, zapcore.Lock(os.Stdout), zap.NewAtomicLevelAt(logLevelMap[logLevel])))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user