-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.go
121 lines (101 loc) · 2.92 KB
/
log.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
package clog
var defaultLogger *Logger
const (
// defaultLogBufferSize sets the buffer size to 2M for the default logger
defaultLogBufferSize = int64(2 * 1024 * 1024)
)
func init() { SetDefaultLogger(nil) }
// SetDefaultLogger sets the logger used when using the package methods
func SetDefaultLogger(logger *Logger) {
if logger == nil {
logger = NewLogger(
newOverflowHandler(
// Discard all log when max buffer size is reached
func(_ *overflowHandler) {
if defaultLogger == logger {
defaultLogger.SetHandler(NewDiscardHandler())
}
},
defaultLogBufferSize,
),
)
defaultLogger = logger
} else {
transferLogFromOverflowHandler(logger.GetHandler(), GetDefaultLogger().GetHandler())
defaultLogger = logger
}
}
// GetDefaultLogger returns the logger used when using the package methods
func GetDefaultLogger() *Logger {
return defaultLogger
}
// SetPrefix sets the output prefix for the standard logger
func SetPrefix(prefix string) *Logger {
defaultLogger.SetPrefix(prefix)
return defaultLogger
}
// Log sends a log entry with the specified level
func Log(level LogLevel, v ...interface{}) {
defaultLog(level, v...)
}
// Logf sends a log entry with the specified level
func Logf(level LogLevel, format string, v ...interface{}) {
defaultLogf(level, format, v...)
}
// Trace sends trace information for heavy debugging
func Trace(v ...interface{}) {
defaultLog(LevelTrace, v...)
}
// Tracef sends trace information for heavy debugging
func Tracef(format string, v ...interface{}) {
defaultLogf(LevelTrace, format, v...)
}
// Debug sends debugging information
func Debug(v ...interface{}) {
defaultLog(LevelDebug, v...)
}
// Debugf sends debugging information
func Debugf(format string, v ...interface{}) {
defaultLogf(LevelDebug, format, v...)
}
// Info logs some noticeable information
func Info(v ...interface{}) {
defaultLog(LevelInfo, v...)
}
// Infof logs some noticeable information
func Infof(format string, v ...interface{}) {
defaultLogf(LevelInfo, format, v...)
}
// Warning send some important message to the console
func Warning(v ...interface{}) {
defaultLog(LevelWarning, v...)
}
// Warningf send some important message to the console
func Warningf(format string, v ...interface{}) {
defaultLogf(LevelWarning, format, v...)
}
// Error sends error information to the console
func Error(v ...interface{}) {
defaultLog(LevelError, v...)
}
// Errorf sends error information to the console
func Errorf(format string, v ...interface{}) {
defaultLogf(LevelError, format, v...)
}
// log is used to keep a constant calldepth
func defaultLog(level LogLevel, v ...interface{}) {
_ = defaultLogger.LogEntry(LogEntry{
Calldepth: 2,
Level: level,
Values: v,
})
}
// logf is used to keep a constant calldepth
func defaultLogf(level LogLevel, format string, v ...interface{}) {
_ = defaultLogger.LogEntry(LogEntry{
Calldepth: 2,
Level: level,
Format: format,
Values: v,
})
}