Skip to content

Commit 8c5e804

Browse files
committed
fix
1 parent 720800d commit 8c5e804

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

logging/logutil/util.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,8 @@ import (
55
"github.com/pubgo/funk"
66
"github.com/pubgo/x/q"
77
"go.uber.org/zap"
8-
"go.uber.org/zap/zapcore"
98
)
109

11-
func Enabled(lvl zapcore.Level, loggers ...*zap.Logger) bool {
12-
var log = zap.L()
13-
if len(loggers) > 0 {
14-
log = loggers[0]
15-
}
16-
return log.Core().Enabled(lvl)
17-
}
18-
1910
func OkOrErr(log *zap.Logger, msg string, fn func() error, fields ...zap.Field) {
2011
log = log.WithOptions(zap.AddCallerSkip(1)).With(fields...)
2112

@@ -112,3 +103,15 @@ func Pretty(a ...interface{}) {
112103
func ColorPretty(args ...interface{}) {
113104
zap.L().WithOptions(zap.AddCallerSkip(1)).Info(string(q.Sq(args...)))
114105
}
106+
107+
func IfDebug(log *zap.Logger, fn func(log *zap.Logger)) {
108+
if log.Core().Enabled(zap.DebugLevel) {
109+
fn(log)
110+
}
111+
}
112+
113+
func IfError(log *zap.Logger, fn func(log *zap.Logger)) {
114+
if log.Core().Enabled(zap.ErrorLevel) {
115+
fn(log)
116+
}
117+
}

0 commit comments

Comments
 (0)