File tree Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Expand file tree Collapse file tree 1 file changed +12
-9
lines changed Original file line number Diff line number Diff 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-
1910func 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{}) {
112103func 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+ }
You can’t perform that action at this time.
0 commit comments