|
|
|
@ -47,25 +47,20 @@ func ZError(ctx context.Context, msg string, err error, keysAndValues ...interfa
|
|
|
|
|
|
|
|
|
|
type ZapLogger struct {
|
|
|
|
|
zap *zap.SugaredLogger
|
|
|
|
|
// store original logger without sampling to avoid multiple samplers
|
|
|
|
|
SampleDuration time.Duration
|
|
|
|
|
SampleInitial int
|
|
|
|
|
SampleInterval int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewZapLogger() (*ZapLogger, error) {
|
|
|
|
|
zapConfig := zap.Config{
|
|
|
|
|
Level: zap.NewAtomicLevelAt(zapcore.DebugLevel),
|
|
|
|
|
Development: true,
|
|
|
|
|
Encoding: "json",
|
|
|
|
|
EncoderConfig: zap.NewProductionEncoderConfig(),
|
|
|
|
|
DisableStacktrace: true,
|
|
|
|
|
InitialFields: map[string]interface{}{"PID": os.Getegid()},
|
|
|
|
|
}
|
|
|
|
|
zl := &ZapLogger{}
|
|
|
|
|
if config.Config.Log.Stderr {
|
|
|
|
|
zapConfig.OutputPaths = append(zapConfig.OutputPaths, "stderr")
|
|
|
|
|
}
|
|
|
|
|
zl := &ZapLogger{}
|
|
|
|
|
opts, err := zl.cores()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -75,13 +70,10 @@ func NewZapLogger() (*ZapLogger, error) {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
zl.zap = l.Sugar()
|
|
|
|
|
zl.zap.WithOptions(zap.AddStacktrace(zap.DPanicLevel))
|
|
|
|
|
return zl, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *ZapLogger) timeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
|
|
|
|
|
enc.AppendString(t.Format("2006-01-02 15:04:05"))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *ZapLogger) cores() (zap.Option, error) {
|
|
|
|
|
c := zap.NewProductionEncoderConfig()
|
|
|
|
|
c.EncodeTime = zapcore.ISO8601TimeEncoder
|
|
|
|
@ -111,6 +103,14 @@ func (l *ZapLogger) cores() (zap.Option, error) {
|
|
|
|
|
}), nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewErrStackCore(c zapcore.Core) zapcore.Core {
|
|
|
|
|
return &errStackCore{c}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type errStackCore struct {
|
|
|
|
|
zapcore.Core
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (l *ZapLogger) getWriter() (zapcore.WriteSyncer, error) {
|
|
|
|
|
logf, err := rotatelogs.New(config.Config.Log.StorageLocation+sp+"OpenIM.log.all"+".%Y-%m-%d",
|
|
|
|
|
rotatelogs.WithRotationCount(config.Config.Log.RemainRotationCount),
|
|
|
|
|