@@ -121,6 +121,8 @@ func (l Level) String() string {
121
121
}
122
122
123
123
// Sink is the destination of a Logger.
124
+ //
125
+ // All sinks must be safe for concurrent use.
124
126
type Sink interface {
125
127
LogEntry (ctx context.Context , e SinkEntry ) error
126
128
Sync () error
@@ -174,6 +176,8 @@ func (s sink) withContext(ctx context.Context) sink {
174
176
175
177
// Logger allows logging a ordered slice of fields
176
178
// to an underlying set of sinks.
179
+ //
180
+ // All Logger's are safe for concurrent use.
177
181
type Logger struct {
178
182
sinks []sink
179
183
skip int
@@ -200,16 +204,22 @@ func (l Logger) Warn(ctx context.Context, msg string, fields ...Field) {
200
204
}
201
205
202
206
// Error logs the msg and fields at LevelError.
207
+ //
208
+ // It will also Sync() before returning.
203
209
func (l Logger ) Error (ctx context.Context , msg string , fields ... Field ) {
204
210
l .log (ctx , LevelError , msg , fields )
205
211
}
206
212
207
213
// Critical logs the msg and fields at LevelCritical.
214
+ //
215
+ // It will also Sync() before returning.
208
216
func (l Logger ) Critical (ctx context.Context , msg string , fields ... Field ) {
209
217
l .log (ctx , LevelCritical , msg , fields )
210
218
}
211
219
212
220
// Fatal logs the msg and fields at LevelFatal.
221
+ //
222
+ // It will also Sync() before returning.
213
223
func (l Logger ) Fatal (ctx context.Context , msg string , fields ... Field ) {
214
224
l .log (ctx , LevelFatal , msg , fields )
215
225
}
@@ -278,8 +288,7 @@ func (l Logger) log(ctx context.Context, level Level, msg string, fields Map) {
278
288
}
279
289
}
280
290
281
- switch level {
282
- case LevelCritical , LevelError , LevelFatal :
291
+ if level >= LevelError {
283
292
l .Sync ()
284
293
if level == LevelFatal {
285
294
exit (1 )
@@ -293,7 +302,7 @@ var errorf = func(f string, v ...interface{}) {
293
302
}
294
303
295
304
// Sync calls Sync on the sinks underlying the logger.
296
- // Used it to ensure all logs are flushed during exit.
305
+ // Use it to ensure all logs are flushed during exit.
297
306
func (l Logger ) Sync () {
298
307
for _ , s := range l .sinks {
299
308
err := s .sink .Sync ()
0 commit comments