Skip to content

Commit 06a737e

Browse files
committed
slog: rename XXXCtx to XXXContext, deprecate old names
See golang/go#61200 for, um, context. Add XXXContext methods, but keep the XXXCtx methods around (deprecated) to avoid breaking people. Change-Id: I6835658615fb4979b03f5ae0516ac8f79b0f241d Reviewed-on: https://go-review.googlesource.com/c/exp/+/508215 Run-TryBot: Jonathan Amsterdam <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent fffb143 commit 06a737e

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

slog/doc.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ argument, as do their corresponding top-level functions.
174174
175175
Although the convenience methods on Logger (Info and so on) and the
176176
corresponding top-level functions do not take a context, the alternatives ending
177-
in "Ctx" do. For example,
177+
in "Context" do. For example,
178178
179-
slog.InfoCtx(ctx, "message")
179+
slog.InfoContext(ctx, "message")
180180
181181
It is recommended to pass a context to an output method if one is available.
182182

slog/logger.go

+55-7
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,13 @@ func (l *Logger) Debug(msg string, args ...any) {
167167
l.log(nil, LevelDebug, msg, args...)
168168
}
169169

170+
// DebugContext logs at LevelDebug with the given context.
171+
func (l *Logger) DebugContext(ctx context.Context, msg string, args ...any) {
172+
l.log(ctx, LevelDebug, msg, args...)
173+
}
174+
170175
// DebugCtx logs at LevelDebug with the given context.
176+
// Deprecated: Use Logger.DebugContext.
171177
func (l *Logger) DebugCtx(ctx context.Context, msg string, args ...any) {
172178
l.log(ctx, LevelDebug, msg, args...)
173179
}
@@ -177,7 +183,13 @@ func (l *Logger) Info(msg string, args ...any) {
177183
l.log(nil, LevelInfo, msg, args...)
178184
}
179185

186+
// InfoContext logs at LevelInfo with the given context.
187+
func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any) {
188+
l.log(ctx, LevelInfo, msg, args...)
189+
}
190+
180191
// InfoCtx logs at LevelInfo with the given context.
192+
// Deprecated: Use Logger.InfoContext.
181193
func (l *Logger) InfoCtx(ctx context.Context, msg string, args ...any) {
182194
l.log(ctx, LevelInfo, msg, args...)
183195
}
@@ -187,7 +199,13 @@ func (l *Logger) Warn(msg string, args ...any) {
187199
l.log(nil, LevelWarn, msg, args...)
188200
}
189201

202+
// WarnContext logs at LevelWarn with the given context.
203+
func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any) {
204+
l.log(ctx, LevelWarn, msg, args...)
205+
}
206+
190207
// WarnCtx logs at LevelWarn with the given context.
208+
// Deprecated: Use Logger.WarnContext.
191209
func (l *Logger) WarnCtx(ctx context.Context, msg string, args ...any) {
192210
l.log(ctx, LevelWarn, msg, args...)
193211
}
@@ -197,7 +215,13 @@ func (l *Logger) Error(msg string, args ...any) {
197215
l.log(nil, LevelError, msg, args...)
198216
}
199217

218+
// ErrorContext logs at LevelError with the given context.
219+
func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any) {
220+
l.log(ctx, LevelError, msg, args...)
221+
}
222+
200223
// ErrorCtx logs at LevelError with the given context.
224+
// Deprecated: Use Logger.ErrorContext.
201225
func (l *Logger) ErrorCtx(ctx context.Context, msg string, args ...any) {
202226
l.log(ctx, LevelError, msg, args...)
203227
}
@@ -249,8 +273,8 @@ func Debug(msg string, args ...any) {
249273
Default().log(nil, LevelDebug, msg, args...)
250274
}
251275

252-
// DebugCtx calls Logger.DebugCtx on the default logger.
253-
func DebugCtx(ctx context.Context, msg string, args ...any) {
276+
// DebugContext calls Logger.DebugContext on the default logger.
277+
func DebugContext(ctx context.Context, msg string, args ...any) {
254278
Default().log(ctx, LevelDebug, msg, args...)
255279
}
256280

@@ -259,8 +283,8 @@ func Info(msg string, args ...any) {
259283
Default().log(nil, LevelInfo, msg, args...)
260284
}
261285

262-
// InfoCtx calls Logger.InfoCtx on the default logger.
263-
func InfoCtx(ctx context.Context, msg string, args ...any) {
286+
// InfoContext calls Logger.InfoContext on the default logger.
287+
func InfoContext(ctx context.Context, msg string, args ...any) {
264288
Default().log(ctx, LevelInfo, msg, args...)
265289
}
266290

@@ -269,8 +293,8 @@ func Warn(msg string, args ...any) {
269293
Default().log(nil, LevelWarn, msg, args...)
270294
}
271295

272-
// WarnCtx calls Logger.WarnCtx on the default logger.
273-
func WarnCtx(ctx context.Context, msg string, args ...any) {
296+
// WarnContext calls Logger.WarnContext on the default logger.
297+
func WarnContext(ctx context.Context, msg string, args ...any) {
274298
Default().log(ctx, LevelWarn, msg, args...)
275299
}
276300

@@ -279,7 +303,31 @@ func Error(msg string, args ...any) {
279303
Default().log(nil, LevelError, msg, args...)
280304
}
281305

282-
// ErrorCtx calls Logger.ErrorCtx on the default logger.
306+
// ErrorContext calls Logger.ErrorContext on the default logger.
307+
func ErrorContext(ctx context.Context, msg string, args ...any) {
308+
Default().log(ctx, LevelError, msg, args...)
309+
}
310+
311+
// DebugCtx calls Logger.DebugContext on the default logger.
312+
// Deprecated: call DebugContext.
313+
func DebugCtx(ctx context.Context, msg string, args ...any) {
314+
Default().log(ctx, LevelDebug, msg, args...)
315+
}
316+
317+
// InfoCtx calls Logger.InfoContext on the default logger.
318+
// Deprecated: call InfoContext.
319+
func InfoCtx(ctx context.Context, msg string, args ...any) {
320+
Default().log(ctx, LevelInfo, msg, args...)
321+
}
322+
323+
// WarnCtx calls Logger.WarnContext on the default logger.
324+
// Deprecated: call WarnContext.
325+
func WarnCtx(ctx context.Context, msg string, args ...any) {
326+
Default().log(ctx, LevelWarn, msg, args...)
327+
}
328+
329+
// ErrorCtx calls Logger.ErrorContext on the default logger.
330+
// Deprecated: call ErrorContext.
283331
func ErrorCtx(ctx context.Context, msg string, args ...any) {
284332
Default().log(ctx, LevelError, msg, args...)
285333
}

0 commit comments

Comments
 (0)