/
options.go
83 lines (71 loc) · 1.5 KB
/
options.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
78
79
80
81
82
83
package logger
var _defOptions = Options{
JsonEncoding: true,
CallerSkipCount: 2,
Level: DebugLevel,
Rotation: Rotation{
MaxSize: 256,
MaxBackups: 300,
MaxAge: 30,
LocalTime: true,
Compress: true,
},
}
type Option func(*Options)
type Options struct {
Debug bool
DisableConsole bool
JsonEncoding bool
CallerSkipCount int
LogDir string
Level string
Fields map[string]any
Rotation Rotation
}
type Rotation struct {
MaxSize int // 单个文件最大尺寸,默认单位 M
MaxBackups int // 最多保留 300 个备份
MaxAge int // 最大时间,默认单位 day
LocalTime bool // 使用本地时间
Compress bool // 是否压缩 disabled by default
}
func WithDebug() Option {
return func(args *Options) {
args.Debug = true
}
}
func WithDisableConsole() Option {
return func(args *Options) {
args.DisableConsole = true
}
}
func WithLogDir(dir string) Option {
return func(args *Options) {
args.LogDir = dir
}
}
func WithJsonEncoding() Option {
return func(args *Options) {
args.JsonEncoding = true
}
}
func WithFields(fields map[string]any) Option {
return func(args *Options) {
args.Fields = fields
}
}
func WithLevel(level string) Option {
return func(args *Options) {
args.Level = level
}
}
func WithCallerSkipCount(c int) Option {
return func(args *Options) {
args.CallerSkipCount = c
}
}
func WithRotation(r Rotation) Option {
return func(args *Options) {
args.Rotation = r
}
}