2 ms·
A link to doc.go, for the lazy: https://cs.opensource.google/go/x/exp/+/645b1fa8:slog/doc.go;l=263 https://cs.opensource.google/go/x/exp/+/645b1fa8:slog/doc.go
by badc0ffee 1y ago
A link to doc.go, for the lazy:
https://cs.opensource.google/go/x/exp/+/645b1fa8:slog/doc.go;l=263 https://cs.opensource.google/go/x/exp/+/645b1fa8:slog/doc.go...
Basically it says to pass in objects, not prepared strings, so the formatted output is only computed if the message is actually logged. That object can be a struct implementing the LogValuer interface to do any required work/produce formatted output.
- lanstin 1y agoOh cool, I hadn't run into LogValuer, that's cool. And passing pointers to strings rather than strings, hmmm.
- 9rx 1y ago> And passing pointers to strings rather than strings, hmmm. Are you referring to the "URL" example? That isn't a case of passing pointers to strings, that is passing a URL (fmt.Stringer) where the String method has a pointer receiver. To demonstrate why the pointer would be needed in that case, consider: type URL struct{} func (*URL) String() string { return "https://..." } func print(v any) { fmt.Println(v.(fmt.Stringer).String()) } func main() { print(&URL{}) // ok print(URL{}) // panic }