Skip to content

Commit

Permalink
feat(contrib/log/zap): If disable this level of logging entirely, avo…
Browse files Browse the repository at this point in the history
…id additional overhead (#3357)
  • Loading branch information
harbourlga committed Sep 2, 2024
1 parent da73565 commit 6963a8a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions contrib/log/zap/zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"

"github.com/go-kratos/kratos/v2/log"
)
Expand Down Expand Up @@ -32,6 +33,11 @@ func NewLogger(zlog *zap.Logger) *Logger {
}

func (l *Logger) Log(level log.Level, keyvals ...interface{}) error {
// If logging at this level is completely disabled, skip the overhead of
// string formatting.
if zapcore.Level(level) < zapcore.DPanicLevel && !l.log.Core().Enabled(zapcore.Level(level)) {
return nil
}
var (
msg = ""
keylen = len(keyvals)
Expand Down

0 comments on commit 6963a8a

Please sign in to comment.