Hi!

I've been playing around with the new slog package, and I noticed that it 
was missing formatter funcs (Infof, Errorf, etc). I'm interested in adding 
these, but I wasn't sure if this was done intentionally since the godoc calls 
out this type of functionality in examples 
<https://pkg.go.dev/log/slog#hdr-Wrapping_output_methods>. 

Helpers have been suggested as a workaround for this 
<https://github.com/golang/go/issues/59145#issuecomment-1481920720>, but 
this is common enough behavior for me that I think it'd be very helpful to 
have upstream to make it easy to do things like: slog.Errorf("error calling 
func: %v", err)

Rough idea would be do expose formatter functions in the Logger 
<https://pkg.go.dev/log/slog#Logger>, with the tradeoff that you replace 
formatter args for Attr args:

```go
func (l *Logger) Errorf(format string, args ...any) {
l.log(context.Background(), LevelError, fmt.Sprintf(msg, args...))
}

func (l *Logger) ErrorContextf(ctx context.Background(ctx context.Context, 
format string, args ...any) {
l.log(ctx, LevelError, fmt.Sprintf(msg, args...))
}
```

I wanted to check in before I opened an issue! 🙏
Let me know if this makes sense, or if there's context I'm missing.

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9316489a-3a0c-4b8e-b789-534662a9bbben%40googlegroups.com.

Reply via email to