This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
logging.go
165 lines (136 loc) · 3.24 KB
/
logging.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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package kook
import (
"net"
"time"
)
//const (
// LogFatal = iota
// LogError
// LogWarning
// LogInfo
// LogDebug
// LogTrace
//)
//var LogFunc func(level, caller int, format string, a ...interface{})
//
//func mlog(level, caller int, format string, a ...interface{}) {
// if LogFunc != nil {
// LogFunc(level, caller, format, a...)
// return
// }
// pc, file, line, _ := runtime.Caller(caller)
//
// files := strings.Split(file, "/")
// file = files[len(files)-1]
//
// name := runtime.FuncForPC(pc).Name()
// fns := strings.Split(name, ".")
// name = fns[len(fns)-1]
//
// msg := fmt.Sprintf(format, a...)
//
// log.Printf("[DG%d] %s:%d:%s() %s\n", level, file, line, name, msg)
//}
//
//func (s *Session) log(level int, format string, a ...interface{}) {
// if level > s.LogLevel {
// return
// }
// mlog(level, 2, format, a...)
//}
func addCaller(e Entry) Entry {
return e.Caller(3)
}
// Logger is the interface which external loggers should meet.
type Logger interface {
Trace() Entry
Debug() Entry
Info() Entry
Warn() Entry
Error() Entry
Fatal() Entry
}
// Entry is the interface which external loggers' entry should meet.
type Entry interface {
Bool(key string, b bool) Entry
Bytes(key string, val []byte) Entry
Caller(depth int) Entry
Dur(key string, d time.Duration) Entry
Err(key string, err error) Entry
Float64(key string, f float64) Entry
IPAddr(key string, ip net.IP) Entry
Int(key string, i int) Entry
Int64(key string, i int64) Entry
Interface(key string, i interface{}) Entry
Msg(msg string)
Msgf(f string, i ...interface{})
Str(key string, s string) Entry
Strs(key string, s []string) Entry
Time(key string, t time.Time) Entry
}
// mock types are only for possible testing usage, do not use it in real project.
// type mockLogger struct {
// }
// func (m mockLogger) Trace() Entry {
// return mockEntry{}
// }
// func (m mockLogger) Debug() Entry {
// return mockEntry{}
// }
// func (m mockLogger) Info() Entry {
// return mockEntry{}
// }
// func (m mockLogger) Warn() Entry {
// return mockEntry{}
// }
// func (m mockLogger) Error() Entry {
// return mockEntry{}
// }
// func (m mockLogger) Fatal() Entry {
// return mockEntry{}
// }
// type mockEntry struct {
// }
// func (m mockEntry) Strs(_ string, _ []string) Entry {
// return m
// }
// func (m mockEntry) Bool(_ string, _ bool) Entry {
// return m
// }
// func (m mockEntry) Bytes(_ string, _ []byte) Entry {
// return m
// }
// func (m mockEntry) Caller(_ int) Entry {
// return m
// }
// func (m mockEntry) Dur(_ string, _ time.Duration) Entry {
// return m
// }
// func (m mockEntry) Err(_ string, _ error) Entry {
// return m
// }
// func (m mockEntry) Float64(_ string, _ float64) Entry {
// return m
// }
// func (m mockEntry) IPAddr(_ string, _ net.IP) Entry {
// return m
// }
// func (m mockEntry) Int(_ string, _ int) Entry {
// return m
// }
// func (m mockEntry) Int64(_ string, _ int64) Entry {
// return m
// }
// func (m mockEntry) Interface(_ string, _ interface{}) Entry {
// return m
// }
// func (m mockEntry) Msg(_ string) {
// }
// func (m mockEntry) Msgf(_ string, _ ...interface{}) {
// }
// func (m mockEntry) Str(_ string, _ string) Entry {
// return m
// }
// func (m mockEntry) Time(_ string, _ time.Time) Entry {
// return m
// }