-
Notifications
You must be signed in to change notification settings - Fork 2
/
options.go
73 lines (60 loc) · 1.31 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
package slogx
import (
"io"
)
// Option is an application option.
type Option func(o *options)
type Options struct {
DisableSource bool
FullSource bool
DisableTime bool
DisableColor bool // for cli
}
// options is an application options.
type options struct {
Options
Level string // debug, info, warn, error
Format string // json, text
Output string // stdout, stderr, discard, or a file path
Writer io.Writer // set this to override Output
Tracing bool // enable tracing feature
}
func WithDisableSource() Option {
return func(o *options) { o.DisableSource = true }
}
func WithFullSource() Option {
return func(o *options) { o.FullSource = true }
}
func WithDisableTime() Option {
return func(o *options) { o.DisableTime = true }
}
func WithLevel(level string) Option {
return func(o *options) {
if level == "" {
level = "info"
}
o.Level = level
}
}
func WithFormat(format string) Option {
return func(o *options) {
if format == "" {
format = "json"
}
o.Format = format
}
}
func WithOutput(output string) Option {
return func(o *options) {
if output == "" {
output = "stderr"
}
o.Output = output
}
}
func WithWriter(w io.Writer) Option {
return func(o *options) { o.Writer = w }
}
func WithTracing() Option {
return func(o *options) { o.Tracing = true }
}