aboutsummaryrefslogtreecommitdiff
path: root/src/log
diff options
context:
space:
mode:
authorJonathan Amsterdam <jba@google.com>2023-07-06 13:06:44 -0400
committerJonathan Amsterdam <jba@google.com>2023-07-11 16:33:46 +0000
commit3f8b04bfb541127704ec5c33a52294fe3c6ebea4 (patch)
treedde0cf6c082e7d8ff9bcd6be10e780c72d02f39a /src/log
parent4c58d6bf52b87628d0a73041af61e58eed84a310 (diff)
downloadgo-3f8b04bfb541127704ec5c33a52294fe3c6ebea4.tar.gz
go-3f8b04bfb541127704ec5c33a52294fe3c6ebea4.zip
log/slog: change XXXCtx functions to XXXContext
Fixes #61200. Change-Id: I3071dbf673bcd2d24e62644b40d481c953703978 Reviewed-on: https://go-review.googlesource.com/c/go/+/508195 Run-TryBot: Jonathan Amsterdam <jba@google.com> Reviewed-by: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/log')
-rw-r--r--src/log/slog/doc.go4
-rw-r--r--src/log/slog/logger.go32
-rw-r--r--src/log/slog/logger_test.go16
3 files changed, 26 insertions, 26 deletions
diff --git a/src/log/slog/doc.go b/src/log/slog/doc.go
index 97c1a0b5ef..d7a2bacb89 100644
--- a/src/log/slog/doc.go
+++ b/src/log/slog/doc.go
@@ -174,9 +174,9 @@ argument, as do their corresponding top-level functions.
Although the convenience methods on Logger (Info and so on) and the
corresponding top-level functions do not take a context, the alternatives ending
-in "Ctx" do. For example,
+in "Context" do. For example,
- slog.InfoCtx(ctx, "message")
+ slog.InfoContext(ctx, "message")
It is recommended to pass a context to an output method if one is available.
diff --git a/src/log/slog/logger.go b/src/log/slog/logger.go
index 2bad5dfccc..b6fea60c9c 100644
--- a/src/log/slog/logger.go
+++ b/src/log/slog/logger.go
@@ -168,8 +168,8 @@ func (l *Logger) Debug(msg string, args ...any) {
l.log(nil, LevelDebug, msg, args...)
}
-// DebugCtx logs at LevelDebug with the given context.
-func (l *Logger) DebugCtx(ctx context.Context, msg string, args ...any) {
+// DebugContext logs at LevelDebug with the given context.
+func (l *Logger) DebugContext(ctx context.Context, msg string, args ...any) {
l.log(ctx, LevelDebug, msg, args...)
}
@@ -178,8 +178,8 @@ func (l *Logger) Info(msg string, args ...any) {
l.log(nil, LevelInfo, msg, args...)
}
-// InfoCtx logs at LevelInfo with the given context.
-func (l *Logger) InfoCtx(ctx context.Context, msg string, args ...any) {
+// InfoContext logs at LevelInfo with the given context.
+func (l *Logger) InfoContext(ctx context.Context, msg string, args ...any) {
l.log(ctx, LevelInfo, msg, args...)
}
@@ -188,8 +188,8 @@ func (l *Logger) Warn(msg string, args ...any) {
l.log(nil, LevelWarn, msg, args...)
}
-// WarnCtx logs at LevelWarn with the given context.
-func (l *Logger) WarnCtx(ctx context.Context, msg string, args ...any) {
+// WarnContext logs at LevelWarn with the given context.
+func (l *Logger) WarnContext(ctx context.Context, msg string, args ...any) {
l.log(ctx, LevelWarn, msg, args...)
}
@@ -198,8 +198,8 @@ func (l *Logger) Error(msg string, args ...any) {
l.log(nil, LevelError, msg, args...)
}
-// ErrorCtx logs at LevelError with the given context.
-func (l *Logger) ErrorCtx(ctx context.Context, msg string, args ...any) {
+// ErrorContext logs at LevelError with the given context.
+func (l *Logger) ErrorContext(ctx context.Context, msg string, args ...any) {
l.log(ctx, LevelError, msg, args...)
}
@@ -250,8 +250,8 @@ func Debug(msg string, args ...any) {
Default().log(nil, LevelDebug, msg, args...)
}
-// DebugCtx calls Logger.DebugCtx on the default logger.
-func DebugCtx(ctx context.Context, msg string, args ...any) {
+// DebugContext calls Logger.DebugContext on the default logger.
+func DebugContext(ctx context.Context, msg string, args ...any) {
Default().log(ctx, LevelDebug, msg, args...)
}
@@ -260,8 +260,8 @@ func Info(msg string, args ...any) {
Default().log(nil, LevelInfo, msg, args...)
}
-// InfoCtx calls Logger.InfoCtx on the default logger.
-func InfoCtx(ctx context.Context, msg string, args ...any) {
+// InfoContext calls Logger.InfoContext on the default logger.
+func InfoContext(ctx context.Context, msg string, args ...any) {
Default().log(ctx, LevelInfo, msg, args...)
}
@@ -270,8 +270,8 @@ func Warn(msg string, args ...any) {
Default().log(nil, LevelWarn, msg, args...)
}
-// WarnCtx calls Logger.WarnCtx on the default logger.
-func WarnCtx(ctx context.Context, msg string, args ...any) {
+// WarnContext calls Logger.WarnContext on the default logger.
+func WarnContext(ctx context.Context, msg string, args ...any) {
Default().log(ctx, LevelWarn, msg, args...)
}
@@ -280,8 +280,8 @@ func Error(msg string, args ...any) {
Default().log(nil, LevelError, msg, args...)
}
-// ErrorCtx calls Logger.ErrorCtx on the default logger.
-func ErrorCtx(ctx context.Context, msg string, args ...any) {
+// ErrorContext calls Logger.ErrorContext on the default logger.
+func ErrorContext(ctx context.Context, msg string, args ...any) {
Default().log(ctx, LevelError, msg, args...)
}
diff --git a/src/log/slog/logger_test.go b/src/log/slog/logger_test.go
index 130f2e6ac8..b8a01dcb4d 100644
--- a/src/log/slog/logger_test.go
+++ b/src/log/slog/logger_test.go
@@ -395,14 +395,14 @@ func TestContext(t *testing.T) {
f func(context.Context, string, ...any)
wantLevel Level
}{
- {l.DebugCtx, LevelDebug},
- {l.InfoCtx, LevelInfo},
- {l.WarnCtx, LevelWarn},
- {l.ErrorCtx, LevelError},
- {DebugCtx, LevelDebug},
- {InfoCtx, LevelInfo},
- {WarnCtx, LevelWarn},
- {ErrorCtx, LevelError},
+ {l.DebugContext, LevelDebug},
+ {l.InfoContext, LevelInfo},
+ {l.WarnContext, LevelWarn},
+ {l.ErrorContext, LevelError},
+ {DebugContext, LevelDebug},
+ {InfoContext, LevelInfo},
+ {WarnContext, LevelWarn},
+ {ErrorContext, LevelError},
} {
h.clear()
ctx := context.WithValue(context.Background(), "L", test.wantLevel)