diff --git a/internal/pkg/log/log.go b/internal/pkg/log/log.go index e3d5794..d92557c 100644 --- a/internal/pkg/log/log.go +++ b/internal/pkg/log/log.go @@ -13,12 +13,25 @@ import ( "time" ) +// Logger define dBlog's logger interface +type Logger interface { + Debugw(msg string, keysAndValues ...interface{}) + Infow(msg string, keysAndValues ...interface{}) + Warnw(msg string, keysAndValues ...interface{}) + Errorw(msg string, keysAndValues ...interface{}) + Panicw(msg string, keysAndValues ...interface{}) + Fatalw(msg string, keysAndValues ...interface{}) + Sync() +} + // zapLogger wraps zap.Logger // the specific implementation of the Logger interface type zapLogger struct { z *zap.Logger } +var _ Logger = (*zapLogger)(nil) + var ( mu sync.Mutex @@ -77,3 +90,59 @@ func NewLogger(opts *Options) *zapLogger { return logger } + +func Sync() { + std.Sync() +} + +func (l *zapLogger) Sync() { + _ = l.z.Sync() +} + +func Debugw(msg string, keysAndValues ...interface{}) { + std.z.Sugar().Debugw(msg, keysAndValues...) +} + +func (l *zapLogger) Debugw(msg string, keysAndValues ...interface{}) { + l.z.Sugar().Debugw(msg, keysAndValues...) +} + +func Infow(msg string, keysAndValues ...interface{}) { + std.z.Sugar().Infow(msg, keysAndValues...) +} + +func (l *zapLogger) Infow(msg string, keysAndValues ...interface{}) { + l.z.Sugar().Infow(msg, keysAndValues...) +} + +func Warnw(msg string, keysAndValues ...interface{}) { + std.z.Sugar().Warnw(msg, keysAndValues...) +} + +func (l *zapLogger) Warnw(msg string, keysAndValues ...interface{}) { + l.z.Sugar().Warnw(msg, keysAndValues...) +} + +func Errorw(msg string, keysAndValues ...interface{}) { + std.z.Sugar().Errorw(msg, keysAndValues...) +} + +func (l *zapLogger) Errorw(msg string, keysAndValues ...interface{}) { + l.z.Sugar().Errorw(msg, keysAndValues...) +} + +func Panicw(msg string, keysAndValues ...interface{}) { + std.z.Sugar().Panicw(msg, keysAndValues...) +} + +func (l *zapLogger) Panicw(msg string, keysAndValues ...interface{}) { + l.z.Sugar().Panicw(msg, keysAndValues...) +} + +func Fatalw(msg string, keysAndValues ...interface{}) { + std.z.Sugar().Fatalw(msg, keysAndValues...) +} + +func (l *zapLogger) Fatalw(msg string, keysAndValues ...interface{}) { + l.z.Sugar().Fatalw(msg, keysAndValues...) +}