Skip to content

Commit

Permalink
feat: update log system - add interface
Browse files Browse the repository at this point in the history
Signed-off-by: daz-3ux <[email protected]>
  • Loading branch information
Daz-3ux committed Sep 8, 2023
1 parent b334ee7 commit ce9cdb4
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions internal/pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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...)
}

0 comments on commit ce9cdb4

Please sign in to comment.