refactored logger wrapper

This commit is contained in:
Evgeniy Kulikov 2020-02-29 18:00:20 +03:00
parent 5a640fc0fa
commit dba58f3935
No known key found for this signature in database
GPG key ID: BF6AEE0A2A699BF2

View file

@ -11,7 +11,8 @@ import (
) )
type zapLogger struct { type zapLogger struct {
log *zap.Logger zapcore.Core
log *zap.SugaredLogger
} }
const ( const (
@ -23,10 +24,12 @@ const (
) )
func gRPCLogger(l *zap.Logger) grpclog.LoggerV2 { func gRPCLogger(l *zap.Logger) grpclog.LoggerV2 {
return &zapLogger{ log := l.WithOptions(
log: l.WithOptions(
// skip gRPCLog + zapLogger in caller // skip gRPCLog + zapLogger in caller
zap.AddCallerSkip(2)), zap.AddCallerSkip(2))
return &zapLogger{
Core: log.Core(),
log: log.Sugar(),
} }
} }
@ -102,60 +105,32 @@ func newLogger(v *viper.Viper) *zap.Logger {
zap.String("app_version", version)) zap.String("app_version", version))
} }
func (z *zapLogger) Info(args ...interface{}) { func (z *zapLogger) Info(args ...interface{}) { z.log.Info(args...) }
z.log.Sugar().Info(args...)
}
func (z *zapLogger) Infoln(args ...interface{}) { func (z *zapLogger) Infoln(args ...interface{}) { z.log.Info(args...) }
z.log.Sugar().Info(args...)
}
func (z *zapLogger) Infof(format string, args ...interface{}) { func (z *zapLogger) Infof(format string, args ...interface{}) { z.log.Infof(format, args...) }
z.log.Sugar().Infof(format, args...)
}
func (z *zapLogger) Println(args ...interface{}) { func (z *zapLogger) Println(args ...interface{}) { z.log.Info(args...) }
z.log.Sugar().Info(args...)
}
func (z *zapLogger) Printf(format string, args ...interface{}) { func (z *zapLogger) Printf(format string, args ...interface{}) { z.log.Infof(format, args...) }
z.log.Sugar().Infof(format, args...)
}
func (z *zapLogger) Warning(args ...interface{}) { func (z *zapLogger) Warning(args ...interface{}) { z.log.Warn(args...) }
z.log.Sugar().Warn(args...)
}
func (z *zapLogger) Warningln(args ...interface{}) { func (z *zapLogger) Warningln(args ...interface{}) { z.log.Warn(args...) }
z.log.Sugar().Warn(args...)
}
func (z *zapLogger) Warningf(format string, args ...interface{}) { func (z *zapLogger) Warningf(format string, args ...interface{}) { z.log.Warnf(format, args...) }
z.log.Sugar().Warnf(format, args...)
}
func (z *zapLogger) Error(args ...interface{}) { func (z *zapLogger) Error(args ...interface{}) { z.log.Error(args...) }
z.log.Sugar().Error(args...)
}
func (z *zapLogger) Errorln(args ...interface{}) { func (z *zapLogger) Errorln(args ...interface{}) { z.log.Error(args...) }
z.log.Sugar().Error(args...)
}
func (z *zapLogger) Errorf(format string, args ...interface{}) { func (z *zapLogger) Errorf(format string, args ...interface{}) { z.log.Errorf(format, args...) }
z.log.Sugar().Errorf(format, args...)
}
func (z *zapLogger) Fatal(args ...interface{}) { func (z *zapLogger) Fatal(args ...interface{}) { z.log.Fatal(args...) }
z.log.Sugar().Fatal(args...)
}
func (z *zapLogger) Fatalln(args ...interface{}) { func (z *zapLogger) Fatalln(args ...interface{}) { z.log.Fatal(args...) }
z.log.Sugar().Fatal(args...)
}
func (z *zapLogger) Fatalf(format string, args ...interface{}) { func (z *zapLogger) Fatalf(format string, args ...interface{}) { z.Fatalf(format, args...) }
z.log.Sugar().Fatalf(format, args...)
}
func (z *zapLogger) V(int) bool { return z.log.Core().Enabled(zapcore.DebugLevel) } func (z *zapLogger) V(int) bool { return z.Enabled(zapcore.DebugLevel) }