Skip to content

Commit 6bc1644

Browse files
committed
Minor documentation improvements
1 parent d963b30 commit 6bc1644

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

slog.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ func (l Level) String() string {
121121
}
122122

123123
// Sink is the destination of a Logger.
124+
//
125+
// All sinks must be safe for concurrent use.
124126
type Sink interface {
125127
LogEntry(ctx context.Context, e SinkEntry) error
126128
Sync() error
@@ -174,6 +176,8 @@ func (s sink) withContext(ctx context.Context) sink {
174176

175177
// Logger allows logging a ordered slice of fields
176178
// to an underlying set of sinks.
179+
//
180+
// All Logger's are safe for concurrent use.
177181
type Logger struct {
178182
sinks []sink
179183
skip int
@@ -200,16 +204,22 @@ func (l Logger) Warn(ctx context.Context, msg string, fields ...Field) {
200204
}
201205

202206
// Error logs the msg and fields at LevelError.
207+
//
208+
// It will also Sync() before returning.
203209
func (l Logger) Error(ctx context.Context, msg string, fields ...Field) {
204210
l.log(ctx, LevelError, msg, fields)
205211
}
206212

207213
// Critical logs the msg and fields at LevelCritical.
214+
//
215+
// It will also Sync() before returning.
208216
func (l Logger) Critical(ctx context.Context, msg string, fields ...Field) {
209217
l.log(ctx, LevelCritical, msg, fields)
210218
}
211219

212220
// Fatal logs the msg and fields at LevelFatal.
221+
//
222+
// It will also Sync() before returning.
213223
func (l Logger) Fatal(ctx context.Context, msg string, fields ...Field) {
214224
l.log(ctx, LevelFatal, msg, fields)
215225
}
@@ -278,8 +288,7 @@ func (l Logger) log(ctx context.Context, level Level, msg string, fields Map) {
278288
}
279289
}
280290

281-
switch level {
282-
case LevelCritical, LevelError, LevelFatal:
291+
if level >= LevelError {
283292
l.Sync()
284293
if level == LevelFatal {
285294
exit(1)
@@ -293,7 +302,7 @@ var errorf = func(f string, v ...interface{}) {
293302
}
294303

295304
// 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.
297306
func (l Logger) Sync() {
298307
for _, s := range l.sinks {
299308
err := s.sink.Sync()

0 commit comments

Comments
 (0)