Skip to content

Commit

Permalink
Merge pull request #7 from FGadvancer/main
Browse files Browse the repository at this point in the history
fix: limit log level to avoid gc alloc memory.
  • Loading branch information
FGadvancer authored Dec 26, 2023
2 parents 156d5ac + f7b0b24 commit 48bea6e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions log/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,25 @@ func (l *ZapLogger) ToZap() *zap.SugaredLogger {
}

func (l *ZapLogger) Debug(ctx context.Context, msg string, keysAndValues ...interface{}) {
if l.level > zapcore.DebugLevel {
return
}
keysAndValues = l.kvAppend(ctx, keysAndValues)
l.zap.Debugw(msg, keysAndValues...)
}

func (l *ZapLogger) Info(ctx context.Context, msg string, keysAndValues ...interface{}) {
if l.level > zapcore.InfoLevel {
return
}
keysAndValues = l.kvAppend(ctx, keysAndValues)
l.zap.Infow(msg, keysAndValues...)
}

func (l *ZapLogger) Warn(ctx context.Context, msg string, err error, keysAndValues ...interface{}) {
if l.level > zapcore.WarnLevel {
return
}
if err != nil {
keysAndValues = append(keysAndValues, "error", err.Error())
}
Expand All @@ -247,6 +256,9 @@ func (l *ZapLogger) Warn(ctx context.Context, msg string, err error, keysAndValu
}

func (l *ZapLogger) Error(ctx context.Context, msg string, err error, keysAndValues ...interface{}) {
if l.level > zapcore.ErrorLevel {
return
}
if err != nil {
keysAndValues = append(keysAndValues, "error", err.Error())
}
Expand Down

0 comments on commit 48bea6e

Please sign in to comment.