Skip to content

Commit dc75814

Browse files
committed
slog: pass Logger as value for With
1 parent e6ec216 commit dc75814

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

slog/benchmarks/benchmarks_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,4 @@ func BenchmarkWith(b *testing.B) {
196196
}
197197
}
198198

199-
var globalLogger *slog.Logger
199+
var globalLogger slog.Logger

slog/logger.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func init() {
2121
}
2222

2323
// Default returns the default Logger.
24-
func Default() *Logger { return defaultLogger.Load().(*Logger) }
24+
func Default() Logger { return *defaultLogger.Load().(*Logger) }
2525

2626
// SetDefault makes l the default Logger.
2727
// After this call, output from the log package's default Logger
@@ -94,7 +94,7 @@ func (l *Logger) Handler() Handler { return l.handler }
9494
// The new Logger shares the old Logger's context.
9595
// The new Logger's handler is the result of calling WithAttrs on the receiver's
9696
// handler.
97-
func (l *Logger) With(args ...any) *Logger {
97+
func (l Logger) With(args ...any) Logger {
9898
var (
9999
attr Attr
100100
attrs []Attr
@@ -103,7 +103,7 @@ func (l *Logger) With(args ...any) *Logger {
103103
attr, args = argsToAttr(args)
104104
attrs = append(attrs, attr)
105105
}
106-
c := l.clone()
106+
c := l
107107
c.handler = l.handler.WithAttrs(attrs)
108108
return c
109109
}
@@ -122,15 +122,15 @@ func (l *Logger) WithGroup(name string) *Logger {
122122
}
123123

124124
// New creates a new Logger with the given non-nil Handler and a nil context.
125-
func New(h Handler) *Logger {
125+
func New(h Handler) Logger {
126126
if h == nil {
127127
panic("nil Handler")
128128
}
129-
return &Logger{handler: h}
129+
return Logger{handler: h}
130130
}
131131

132132
// With calls Logger.With on the default logger.
133-
func With(args ...any) *Logger {
133+
func With(args ...any) Logger {
134134
return Default().With(args...)
135135
}
136136

@@ -211,7 +211,7 @@ func (l *Logger) ErrorCtx(ctx context.Context, msg string, args ...any) {
211211
// log is the low-level logging method for methods that take ...any.
212212
// It must always be called directly by an exported logging method
213213
// or function, because it uses a fixed call depth to obtain the pc.
214-
func (l *Logger) log(ctx context.Context, level Level, msg string, args ...any) {
214+
func (l Logger) log(ctx context.Context, level Level, msg string, args ...any) {
215215
if !l.Enabled(ctx, level) {
216216
return
217217
}
@@ -231,7 +231,7 @@ func (l *Logger) log(ctx context.Context, level Level, msg string, args ...any)
231231
}
232232

233233
// logAttrs is like [Logger.log], but for methods that take ...Attr.
234-
func (l *Logger) logAttrs(ctx context.Context, level Level, msg string, attrs ...Attr) {
234+
func (l Logger) logAttrs(ctx context.Context, level Level, msg string, attrs ...Attr) {
235235
if !l.Enabled(ctx, level) {
236236
return
237237
}

0 commit comments

Comments
 (0)