mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
zap
This commit is contained in:
parent
fb668b3f0c
commit
f4020a2508
@ -20,7 +20,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
_levelToColor = map[zapcore.Level]Color{
|
_levelToColor = map[zapcore.Level]Color{
|
||||||
zapcore.DebugLevel: Magenta,
|
zapcore.DebugLevel: White,
|
||||||
zapcore.InfoLevel: Blue,
|
zapcore.InfoLevel: Blue,
|
||||||
zapcore.WarnLevel: Yellow,
|
zapcore.WarnLevel: Yellow,
|
||||||
zapcore.ErrorLevel: Red,
|
zapcore.ErrorLevel: Red,
|
||||||
|
@ -60,8 +60,6 @@ func ZError(ctx context.Context, msg string, err error, keysAndValues ...interfa
|
|||||||
type ZapLogger struct {
|
type ZapLogger struct {
|
||||||
zap *zap.SugaredLogger
|
zap *zap.SugaredLogger
|
||||||
level zapcore.Level
|
level zapcore.Level
|
||||||
callerKey string
|
|
||||||
loggerKey string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewZapLogger(logLevel int, isStdout bool, isJson bool, logLocation string, rotateCount uint) (*ZapLogger, error) {
|
func NewZapLogger(logLevel int, isStdout bool, isJson bool, logLocation string, rotateCount uint) (*ZapLogger, error) {
|
||||||
@ -99,10 +97,6 @@ func (l *ZapLogger) cores(isStdout bool, isJson bool, logLocation string, rotate
|
|||||||
c.MessageKey = "msg"
|
c.MessageKey = "msg"
|
||||||
c.LevelKey = "level"
|
c.LevelKey = "level"
|
||||||
c.TimeKey = "time"
|
c.TimeKey = "time"
|
||||||
l.callerKey = "caller"
|
|
||||||
l.loggerKey = "logger"
|
|
||||||
c.CallerKey = l.callerKey
|
|
||||||
l.loggerKey = c.NameKey
|
|
||||||
|
|
||||||
var fileEncoder zapcore.Encoder
|
var fileEncoder zapcore.Encoder
|
||||||
if isJson {
|
if isJson {
|
||||||
@ -112,13 +106,12 @@ func (l *ZapLogger) cores(isStdout bool, isJson bool, logLocation string, rotate
|
|||||||
c.EncodeLevel = l.CapitalColorLevelEncoder
|
c.EncodeLevel = l.CapitalColorLevelEncoder
|
||||||
customCallerEncoder := func(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) {
|
customCallerEncoder := func(caller zapcore.EntryCaller, enc zapcore.PrimitiveArrayEncoder) {
|
||||||
s := "[" + caller.TrimmedPath() + "]"
|
s := "[" + caller.TrimmedPath() + "]"
|
||||||
pid := fmt.Sprintf("["+"PID:"+"%d"+"]", os.Getpid())
|
|
||||||
color, ok := _levelToColor[l.level]
|
color, ok := _levelToColor[l.level]
|
||||||
if !ok {
|
if !ok {
|
||||||
color = _levelToColor[zapcore.ErrorLevel]
|
color = _levelToColor[zapcore.ErrorLevel]
|
||||||
}
|
}
|
||||||
enc.AppendString(color.Add(s))
|
enc.AppendString(color.Add(s))
|
||||||
enc.AppendString(color.Add(pid))
|
|
||||||
}
|
}
|
||||||
c.EncodeCaller = customCallerEncoder
|
c.EncodeCaller = customCallerEncoder
|
||||||
fileEncoder = zapcore.NewConsoleEncoder(c)
|
fileEncoder = zapcore.NewConsoleEncoder(c)
|
||||||
@ -161,7 +154,9 @@ func (l *ZapLogger) CapitalColorLevelEncoder(level zapcore.Level, enc zapcore.Pr
|
|||||||
if !ok {
|
if !ok {
|
||||||
s = _unknownLevelColor[zapcore.ErrorLevel]
|
s = _unknownLevelColor[zapcore.ErrorLevel]
|
||||||
}
|
}
|
||||||
|
pid := fmt.Sprintf("["+"PID:"+"%d"+"]", os.Getpid())
|
||||||
|
color := _levelToColor[level]
|
||||||
|
enc.AppendString(color.Add(pid))
|
||||||
enc.AppendString(s)
|
enc.AppendString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user