-
Notifications
You must be signed in to change notification settings - Fork 8
/
field.go
83 lines (73 loc) · 1.99 KB
/
field.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 logs
import (
"github.com/zxysilent/logs/internal/buffer"
"github.com/zxysilent/logs/internal/encoder"
)
type FieldLogger struct {
attr *buffer.Buffer //调用输出后清空
buf *buffer.Buffer //每次输出的时候重置
logger *Logger
enc encoder.Encoder
trace string
caller bool
}
func (s *FieldLogger) Caller(b bool) *FieldLogger {
s.caller = b
return s
}
func (fl *FieldLogger) Debug(args ...any) {
if LDEBUG >= fl.logger.level {
print(fl.trace, LDEBUG, fl.caller, fl.logger, fl.attr, args...)
}
buffer.Put(fl.attr)
fl.attr = nil
}
func (fl *FieldLogger) Debugf(foramt string, args ...any) {
if LDEBUG >= fl.logger.level {
printf(fl.trace, LDEBUG, fl.caller, fl.logger, fl.attr, foramt, args...)
}
buffer.Put(fl.attr)
fl.attr = nil
}
func (fl *FieldLogger) Info(args ...any) {
if LINFO >= fl.logger.level {
print(fl.trace, LINFO, fl.caller, fl.logger, fl.attr, args...)
}
buffer.Put(fl.attr)
fl.attr = nil
}
func (fl *FieldLogger) Infof(foramt string, args ...any) {
if LINFO >= fl.logger.level {
printf(fl.trace, LINFO, fl.caller, fl.logger, fl.attr, foramt, args...)
}
buffer.Put(fl.attr)
fl.attr = nil
}
func (fl *FieldLogger) Warn(args ...any) {
if LWARN >= fl.logger.level {
print(fl.trace, LWARN, fl.caller, fl.logger, fl.attr, args...)
}
buffer.Put(fl.attr)
fl.attr = nil
}
func (fl *FieldLogger) Warnf(foramt string, args ...any) {
if LWARN >= fl.logger.level {
printf(fl.trace, LWARN, fl.caller, fl.logger, fl.attr, foramt, args...)
}
buffer.Put(fl.attr)
fl.attr = nil
}
func (fl *FieldLogger) Error(args ...any) {
if LERROR >= fl.logger.level {
print(fl.trace, LERROR, fl.caller, fl.logger, fl.attr, args...)
}
buffer.Put(fl.attr)
fl.attr = nil
}
func (fl *FieldLogger) Errorf(foramt string, args ...any) {
if LERROR >= fl.logger.level {
printf(fl.trace, LERROR, fl.caller, fl.logger, fl.attr, foramt, args...)
}
buffer.Put(fl.attr)
fl.attr = nil
}