@@ -172,50 +172,55 @@ func kvFuncSkipArgs(fn *types.Func) (int, bool) {
172
172
if pkg := fn .Pkg (); pkg == nil || pkg .Path () != "log/slog" {
173
173
return 0 , false
174
174
}
175
+ var recvName string // by default a slog package function
175
176
recv := fn .Type ().(* types.Signature ).Recv ()
176
- if recv == nil {
177
- if fn .Name () == "Group" {
178
- return 0 , true
177
+ if recv != nil {
178
+ t := recv .Type ()
179
+ if pt , ok := t .(* types.Pointer ); ok {
180
+ t = pt .Elem ()
179
181
}
180
- skip , ok := slogOutputFuncs [fn .Name ()]
181
- return skip , ok
182
- }
183
- var recvName string
184
- if pt , ok := recv .Type ().(* types.Pointer ); ok {
185
- if nt , ok := pt .Elem ().(* types.Named ); ok {
182
+ if nt , ok := t .(* types.Named ); ! ok {
183
+ return 0 , false
184
+ } else {
186
185
recvName = nt .Obj ().Name ()
187
186
}
188
187
}
189
- if recvName == "" {
190
- return 0 , false
191
- }
192
- // The methods on *Logger include all the top-level output methods, as well as "With".
193
- if recvName == "Logger" {
194
- if fn .Name () == "With" {
195
- return 0 , true
196
- }
197
- skip , ok := slogOutputFuncs [fn .Name ()]
198
- return skip , ok
199
- }
200
- if recvName == "Record" && fn .Name () == "Add" {
201
- return 0 , true
202
- }
203
- return 0 , false
188
+ skip , ok := kvFuncs [recvName ][fn .Name ()]
189
+ return skip , ok
204
190
}
205
191
206
- // The names of top-level functions and *Logger methods in log/slog that take
192
+ // The names of functions and methods in log/slog that take
207
193
// ...any for key-value pairs, mapped to the number of initial args to skip in
208
194
// order to get to the ones that match the ...any parameter.
209
- var slogOutputFuncs = map [string ]int {
210
- "Debug" : 1 ,
211
- "Info" : 1 ,
212
- "Warn" : 1 ,
213
- "Error" : 1 ,
214
- "DebugCtx" : 2 ,
215
- "InfoCtx" : 2 ,
216
- "WarnCtx" : 2 ,
217
- "ErrorCtx" : 2 ,
218
- "Log" : 3 ,
195
+ // The first key is the dereferenced receiver type name, or "" for a function.
196
+ var kvFuncs = map [string ]map [string ]int {
197
+ "" : map [string ]int {
198
+ "Debug" : 1 ,
199
+ "Info" : 1 ,
200
+ "Warn" : 1 ,
201
+ "Error" : 1 ,
202
+ "DebugCtx" : 2 ,
203
+ "InfoCtx" : 2 ,
204
+ "WarnCtx" : 2 ,
205
+ "ErrorCtx" : 2 ,
206
+ "Log" : 3 ,
207
+ "Group" : 0 ,
208
+ },
209
+ "Logger" : map [string ]int {
210
+ "Debug" : 1 ,
211
+ "Info" : 1 ,
212
+ "Warn" : 1 ,
213
+ "Error" : 1 ,
214
+ "DebugCtx" : 2 ,
215
+ "InfoCtx" : 2 ,
216
+ "WarnCtx" : 2 ,
217
+ "ErrorCtx" : 2 ,
218
+ "Log" : 3 ,
219
+ "With" : 0 ,
220
+ },
221
+ "Record" : map [string ]int {
222
+ "Add" : 0 ,
223
+ },
219
224
}
220
225
221
226
// isMethodExpr reports whether a call is to a MethodExpr.
0 commit comments