-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions.go
More file actions
146 lines (125 loc) · 2.84 KB
/
options.go
File metadata and controls
146 lines (125 loc) · 2.84 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package shandler
import (
"io"
"log/slog"
)
func WithJSON() HandlerOption {
return func(h *Handler) {
h.json = true
}
}
func WithPid() HandlerOption {
return func(h *Handler) {
h.pid = true
}
}
func WithStdOut(out ...io.Writer) HandlerOption {
return func(h *Handler) {
h.out = out
}
}
func WithStdErr(err ...io.Writer) HandlerOption {
return func(h *Handler) {
h.err = err
}
}
func WithTimeFormat(format string) HandlerOption {
return func(h *Handler) {
h.timeFormat = format
}
}
func WithLineInfo(short bool) HandlerOption {
return func(h *Handler) {
h.lineInfo = true
h.lineInfoShort = short
}
}
// WithTextOutputFormat sets the format for the group output.
// The order of the fields are:
// 1. Record Level (Debug, Info, Warn, Error)
// 2. Record Time
// 3. Record Message
//
// The default format is "[%s] %s - %s\n".
// If you want to rearrange the fields, you can use the indexes:
// "%[3]s %[1]s %[2]\n"
// This will output "{Record Message} {Record Level} {Record Time}\n"
//
// User must provide newline in format
func WithTextOutputFormat(format string) HandlerOption {
return func(h *Handler) {
h.textOutputFormat = format
}
}
func WithGroupTextOutputFormat(format string) HandlerOption {
return func(h *Handler) {
h.groupTextOutputFormat = format
}
}
// WithGroupRightJustify will right justify the group name if set
// If there is an error calculating the width, it will default to 80
//
// Will override WithGroupTextOutputFormat setting if set
func WithGroupRightJustify() HandlerOption {
return func(h *Handler) {
h.groupRightJustify = true
}
}
func WithLogLevel(level slog.Level) HandlerOption {
return func(h *Handler) {
h.level = level
}
}
func WithColor() HandlerOption {
return func(h *Handler) {
h.color = true
}
}
func WithTraceColor(color string) HandlerOption {
return func(h *Handler) {
h.traceColor = color
}
}
func WithDebugColor(color string) HandlerOption {
return func(h *Handler) {
h.debugColor = color
}
}
func WithInfoColor(color string) HandlerOption {
return func(h *Handler) {
h.infoColor = color
}
}
func WithWarnColor(color string) HandlerOption {
return func(h *Handler) {
h.warnColor = color
}
}
func WithErrorColor(color string) HandlerOption {
return func(h *Handler) {
h.errorColor = color
}
}
func WithFatalColor(color string) HandlerOption {
return func(h *Handler) {
h.fatalColor = color
}
}
func WithShortLevels() HandlerOption {
return func(h *Handler) {
h.shortLevels = true
}
}
// You can use this to filter out logs from specific groups
func WithGroupFilter(filter []string) HandlerOption {
return func(h *Handler) {
h.groupFilter = filter
}
}
// The handler will append a "error_id" field to the log record
// with a unique id for the error for easier tracking
func WithErrorTag() HandlerOption {
return func(h *Handler) {
h.errorTag = true
}
}