-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathloggers.go
More file actions
184 lines (158 loc) · 5.12 KB
/
loggers.go
File metadata and controls
184 lines (158 loc) · 5.12 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
Basic Logging
Loging helpers exist for the following levels:
Emergency + (fatal/panic)
Alert + (fatal/panic)
Critical + (fatal/panic)
Error + (fatal/panic)
Warning
Notice
Info
Debug
These methods accept both strings (message content,) or types that
implement the message.MessageComposer interface. Composer types make
it possible to delay generating a message unless the logger is over
the logging threshold. Use this to avoid expensive serialization
operations for suppressed logging operations.
All levels also have additional methods with `ln` and `f` appended to
the end of the method name which allow Println() and Printf() style
functionality. You must pass printf/println-style arguments to these methods.
# Conditional Logging
The Conditional logging methods take two arguments, a Boolean, and a
message argument. Messages can be strings, objects that implement the
MessageComposer interface, or errors. If condition boolean is true,
the threshold level is met, and the message to log is not an empty
string, then it logs the resolved message.
Use conditional logging methods to potentially suppress log messages
based on situations orthogonal to log level, with "log sometimes" or
"log rarely" semantics. Combine with MessageComposers to to avoid
expensive message building operations.
*/
package grip
import (
"context"
"github.com/mongodb/grip/level"
)
func Log(ctx context.Context, l level.Priority, msg interface{}) {
std.Log(ctx, l, msg)
}
func Logf(ctx context.Context, l level.Priority, msg string, a ...interface{}) {
std.Logf(ctx, l, msg, a...)
}
func Logln(ctx context.Context, l level.Priority, a ...interface{}) {
std.Logln(ctx, l, a...)
}
func LogWhen(ctx context.Context, conditional bool, l level.Priority, m interface{}) {
std.LogWhen(ctx, conditional, l, m)
}
// Leveled Logging Methods
// Emergency-level logging methods
func EmergencyFatal(ctx context.Context, msg interface{}) {
std.EmergencyFatal(ctx, msg)
}
func Emergency(ctx context.Context, msg interface{}) {
std.Emergency(ctx, msg)
}
func Emergencyf(ctx context.Context, msg string, a ...interface{}) {
std.Emergencyf(ctx, msg, a...)
}
func Emergencyln(ctx context.Context, a ...interface{}) {
std.Emergencyln(ctx, a...)
}
func EmergencyPanic(ctx context.Context, msg interface{}) {
std.EmergencyPanic(ctx, msg)
}
func EmergencyWhen(ctx context.Context, conditional bool, m interface{}) {
std.EmergencyWhen(ctx, conditional, m)
}
// Alert-level logging methods
func Alert(ctx context.Context, msg interface{}) {
std.Alert(ctx, msg)
}
func Alertf(ctx context.Context, msg string, a ...interface{}) {
std.Alertf(ctx, msg, a...)
}
func Alertln(ctx context.Context, a ...interface{}) {
std.Alertln(ctx, a...)
}
func AlertWhen(ctx context.Context, conditional bool, m interface{}) {
std.AlertWhen(ctx, conditional, m)
}
// Critical-level logging methods
func Critical(ctx context.Context, msg interface{}) {
std.Critical(ctx, msg)
}
func Criticalf(ctx context.Context, msg string, a ...interface{}) {
std.Criticalf(ctx, msg, a...)
}
func Criticalln(ctx context.Context, a ...interface{}) {
std.Criticalln(ctx, a...)
}
func CriticalWhen(ctx context.Context, conditional bool, m interface{}) {
std.CriticalWhen(ctx, conditional, m)
}
// Error-level logging methods
func Error(ctx context.Context, msg interface{}) {
std.Error(ctx, msg)
}
func Errorf(ctx context.Context, msg string, a ...interface{}) {
std.Errorf(ctx, msg, a...)
}
func Errorln(ctx context.Context, a ...interface{}) {
std.Errorln(ctx, a...)
}
func ErrorWhen(ctx context.Context, conditional bool, m interface{}) {
std.ErrorWhen(ctx, conditional, m)
}
// Warning-level logging methods
func Warning(ctx context.Context, msg interface{}) {
std.Warning(ctx, msg)
}
func Warningf(ctx context.Context, msg string, a ...interface{}) {
std.Warningf(ctx, msg, a...)
}
func Warningln(ctx context.Context, a ...interface{}) {
std.Warningln(ctx, a...)
}
func WarningWhen(ctx context.Context, conditional bool, m interface{}) {
std.WarningWhen(ctx, conditional, m)
}
// Notice-level logging methods
func Notice(ctx context.Context, msg interface{}) {
std.Notice(ctx, msg)
}
func Noticef(ctx context.Context, msg string, a ...interface{}) {
std.Noticef(ctx, msg, a...)
}
func Noticeln(ctx context.Context, a ...interface{}) {
std.Noticeln(ctx, a...)
}
func NoticeWhen(ctx context.Context, conditional bool, m interface{}) {
std.NoticeWhen(ctx, conditional, m)
}
// Info-level logging methods
func Info(ctx context.Context, msg interface{}) {
std.Info(ctx, msg)
}
func Infof(ctx context.Context, msg string, a ...interface{}) {
std.Infof(ctx, msg, a...)
}
func Infoln(ctx context.Context, a ...interface{}) {
std.Infoln(ctx, a...)
}
func InfoWhen(ctx context.Context, conditional bool, message interface{}) {
std.InfoWhen(ctx, conditional, message)
}
// Debug-level logging methods
func Debug(ctx context.Context, msg interface{}) {
std.Debug(ctx, msg)
}
func Debugf(ctx context.Context, msg string, a ...interface{}) {
std.Debugf(ctx, msg, a...)
}
func Debugln(ctx context.Context, a ...interface{}) {
std.Debugln(ctx, a...)
}
func DebugWhen(ctx context.Context, conditional bool, m interface{}) {
std.DebugWhen(ctx, conditional, m)
}