-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
68 lines (58 loc) · 1.69 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
package bilog
type loggerConfig struct {
tt timeTemplate
st sourceTemplate
lowBufferSize int
topBufferSize int
}
// 输出时间的模板
type timeTemplate struct {
start bool
region int
}
// 显示源代码行号的模板
type sourceTemplate struct {
start bool
skip int
split byte
}
type WithFunc func(options *loggerConfig)
func (w WithFunc) apply(options *loggerConfig) {
w(options)
}
func WithDefault() WithFunc {
return func(options *loggerConfig) {
options.tt.start = true
options.st.start = false
options.st.skip = defaultCallDepth
options.lowBufferSize = DEFAULT_LOW_BUFFER_SIZE
options.topBufferSize = DEFAULT_TOP_BUFFER_SIZE
}
}
// WithCaller 指定是否输出源代码文件/行号信息, offSet指定在默认输出深度上的偏移值
// 有默认值是因为bilog内部在调用runtime.Callers时也有一定深度的封装, 这导致需要调整寻找的栈深度
func WithCaller(offSet int) WithFunc {
return func(options *loggerConfig) {
options.st.start = true
options.st.skip = defaultCallDepth + offSet
}
}
func WithTimes() WithFunc {
return func(options *loggerConfig) {
options.tt.start = true
}
}
// WithLowBuffer 大小可已设置为 N * DEFAULT_TOP_BUFFER_SIZE
// nTopBuffer == N
func WithLowBuffer(nTopBuffer int8) WithFunc {
return func(options *loggerConfig) {
options.lowBufferSize = int(nTopBuffer) * DEFAULT_TOP_BUFFER_SIZE
}
}
// WithTopBuffer 原来的pow语义不够清晰,设置0-Buffer时无法提供一个清晰的语义
// 所以将其改成直接设置Top-Buffer的大小
func WithTopBuffer(lowBufferSize int32) WithFunc {
return func(options *loggerConfig) {
options.topBufferSize = int(lowBufferSize)
}
}