Another idea: write a handler that wraps whatever handler you usually use. That handler looks through the Record for attr values of type *http.Request, and replaces them with whatever formatting you want. You might even be able to do that with a ReplaceAttr function with the built-in handlers.
On Sat, Jul 29, 2023 at 10:23 AM Jens-Uwe Mager <juma...@gmail.com> wrote: > There is a slight problem here that the requestWrapper would have to be > implemented very deep through many layers of library. For example there > might be a data structure passed down a chain of handlers with a custom > argument structure, which contains a http.Request per some old design > decisions. Switching to slog probably makes me revisit this design, as I > cannot easily get the http.Request out of that structure easily. And this > custom structure is logged all over the place. > > Oh well. > > On Saturday, July 29, 2023 at 12:18:53 PM UTC+2 Jonathan Amsterdam wrote: > >> I would write a type that wraps the request and implements LogValuer. >> Then you would log the request as >> >> logger.Debug("req", "r", requestWrapper{r}) >> >> On Thursday, July 27, 2023 at 10:01:27 AM UTC-4 Jens-Uwe Mager wrote: >> >>> I am trying to convert some older code to slog and I am running into the >>> issue that if some data structure contains http.Request I get the message: >>> >>> {"time":"2023-07-27T15:49:04.744214+02:00","level":"DEBUG","msg":"req","r":"!ERROR:json: >>> unsupported type: func() (io.ReadCloser, error)"} >>> >>> So I believed it would be a good idea to add a LogValue() function to >>> http.Request that used httputil.DumpRequest(), but that does not work as I >>> cannot add methods from my code. Any good idea to approach that? >>> >>> -- > You received this message because you are subscribed to a topic in the > Google Groups "golang-nuts" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/golang-nuts/PYIIhY6pNM4/unsubscribe. > To unsubscribe from this group and all its topics, 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/a42d3bce-86d0-43dd-8895-4bd3a524cddfn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/a42d3bce-86d0-43dd-8895-4bd3a524cddfn%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/CAOqyxwLibjE7TCFy5kiGsgORYzb2O5-EptBOZ2chT6tuQEaeZg%40mail.gmail.com.