@@ -66,22 +66,24 @@ func (l *Logger) Handler() Handler { return l.handler }
66
66
// With returns a new Logger whose handler's attributes are a concatenation of
67
67
// l's attributes and the given arguments, converted to Attrs as in
68
68
// [Logger.Log].
69
- func (l * Logger ) With (attrs ... any ) * Logger {
70
- return & Logger {handler : l .handler .With (argsToAttrs (attrs ))}
71
- }
72
-
73
- func argsToAttrs (args []any ) []Attr {
74
- var r Record
75
- setAttrs (& r , args )
76
- return r .Attrs ()
69
+ func (l * Logger ) With (args ... any ) * Logger {
70
+ var (
71
+ attr Attr
72
+ attrs []Attr
73
+ )
74
+ for len (args ) > 0 {
75
+ attr , args = argsToAttr (args )
76
+ attrs = append (attrs , attr )
77
+ }
78
+ return & Logger {handler : l .handler .With (attrs )}
77
79
}
78
80
79
81
// New creates a new Logger with the given Handler.
80
82
func New (h Handler ) * Logger { return & Logger {handler : h } }
81
83
82
84
// With calls Logger.With on the default logger.
83
- func With (attrs ... any ) * Logger {
84
- return Default ().With (attrs ... )
85
+ func With (args ... any ) * Logger {
86
+ return Default ().With (args ... )
85
87
}
86
88
87
89
// Enabled reports whether l emits log records at the given level.
@@ -138,7 +140,7 @@ func setAttrs(r *Record, args []any) {
138
140
}
139
141
}
140
142
141
- // argsToAttrs turns a prefix of the args slice into an Attr and returns
143
+ // argsToAttr turns a prefix of the args slice into an Attr and returns
142
144
// the unused portion of the slice.
143
145
// If args[0] is an Attr, it returns it.
144
146
// If args[0] is a string, it treats the first two elements as
0 commit comments