/
cfg.go
70 lines (60 loc) 路 1.08 KB
/
cfg.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
package wlog
import (
"strings"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type Config struct {
Name string
Level Level
File string
RotateConfig *RotateConfig
Wrappers []func(*zap.Logger) *zap.Logger
}
// RotateConfig config log rotate
type RotateConfig struct {
Compress bool
MaxAge int
MaxSize int
MaxBackups int
}
type Level uint
const (
DebugLevel Level = iota
InfoLevel
WarnLevel
ErrorLevel
PanicLevel
)
func (l Level) zaplevel() zapcore.Level {
switch l {
case DebugLevel:
return zapcore.DebugLevel
case InfoLevel:
return zapcore.InfoLevel
case WarnLevel:
return zapcore.WarnLevel
case ErrorLevel:
return zapcore.ErrorLevel
case PanicLevel:
return zapcore.PanicLevel
}
return zapcore.InfoLevel
}
// ParseLevel parse level string
func ParseLevel(str string) Level {
switch strings.ToLower(str) {
case "debug":
return DebugLevel
case "info":
return InfoLevel
case "warn":
return WarnLevel
case "error":
return ErrorLevel
case "panic":
return PanicLevel
}
// Default log level
return InfoLevel
}