-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathoptions.go
57 lines (48 loc) · 1.3 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
package logx
import "io"
// Option is the common type of functions that set options
type Option func(*options)
type options struct {
marshaler Marshaler
writer io.Writer
level Level
withoutTime bool
withoutFileInfo bool
additionalFileSkipLevel int
}
// MarshalerOpt is an option that changes the log marshaler.
func MarshalerOpt(m Marshaler) Option {
return func(o *options) {
o.marshaler = m
}
}
// WriterOpt is an option that changes the log writer.
func WriterOpt(w io.Writer) Option {
return func(o *options) {
o.writer = w
}
}
// LevelOpt is an option that changes the log level.
func LevelOpt(l Level) Option {
return func(o *options) {
o.level = l
}
}
// WithoutTimeOpt is an option that removes time logging for testing purposes.
func WithoutTimeOpt() Option {
return func(o *options) {
o.withoutTime = true
}
}
// WithoutFileInfo is an option that disables logging the file and line where the log was called.
func WithoutFileInfo() Option {
return func(o *options) {
o.withoutFileInfo = true
}
}
// AdditionalFileSkipLevel is an option that lets you go more levels up to find the file & line doing the log.
func AdditionalFileSkipLevel(l int) Option {
return func(o *options) {
o.additionalFileSkipLevel = l
}
}