-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
77 lines (65 loc) · 2.08 KB
/
interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* @Author: jinde.zgm
* @Date: 2020-11-22 14:09:48
* @Descripttion:
*/
package levelzap
import (
"flag"
"go.uber.org/zap/zapcore"
)
// Interface define leveled zap.Logger.
type Interface interface {
// InitFlags is for explicitly initializing the flags.
InitFlags(flagset *flag.FlagSet)
// SetEncoderConfig will set the custom encoder config for zap.
SetEncoderConfig(config zapcore.EncoderConfig)
// AddCallerSkip increases the number of callers skipped by caller annotation
AddCallerSkip(skip int)
// SetLevel set number for the log level verbosity
SetLevel(l Level)
// V reports whether verbosity at the call site is at least the requested level.
// The returned value is a *zap.Logger of type Verbose, which implements Info, Panic
// and Fatal. These methods will write to the Info log if called.
V(l Level) *Verbose
// Flush flushes all pending log I/O.
Flush()
}
// levelzap uses the log level defined by zap by default.
// The log level can be customized through the SetLevel() and V() interfaces.
const (
DEBUG Level = Level(zapcore.DebugLevel)
INFO Level = Level(zapcore.InfoLevel)
WARN Level = Level(zapcore.WarnLevel)
ERROR Level = Level(zapcore.ErrorLevel)
PANIC Level = Level(zapcore.PanicLevel)
FATAL Level = Level(zapcore.FatalLevel)
)
// New create levelzap object.
func New() Interface {
l := &loggingT{}
l.initDefault()
return l
}
// By default, levelzap will create an Interface named logging for applications that only have one log object.
// Levelzap opens the logging's interfaces as global functions.
// InitFlags initialize logging flags.
func InitFlags(flagset *flag.FlagSet) {
logging.InitFlags(flagset)
}
// SetEncoderConfig set logging custom encoder config.
func SetEncoderConfig(config zapcore.EncoderConfig) {
logging.SetEncoderConfig(config)
}
// SetLevel set logging log level.
func SetLevel(l Level) {
logging.SetLevel(l)
}
// V reports whether logging verbosity at the call site is at least the requested level.
func V(level Level) *Verbose {
return logging.V(level)
}
// Flush flushes logging all pending log I/O.
func Flush() {
logging.Flush()
}