I believe the intention is that you shouldn't format this, but make `err`
an `Attr`. i.e. the philosophy behind structured logging is specifically,
not to do formatting, as it produces unstructured data. Whether I'm
personally convinced by that philosophy is another question, but I think
that's the reason these where left out.

On Wed, Dec 13, 2023 at 3:30 AM 'Billy Lynch' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> 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
> <https://groups.google.com/d/msgid/golang-nuts/9316489a-3a0c-4b8e-b789-534662a9bbben%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAEkBMfGQ-hs-C1cEy_WLWWX4Gj9ZP7%3DspyUgdv2s7Zs3TdHP0g%40mail.gmail.com.

Reply via email to