|
|
|
|
|
by sveinnthorarins
278 days ago
|
|
Cool article. I really like structured logs and am pleased the Go team saw the benefits of bringing it into the standard library. However, I feel like errors should be able to hold slog attributes. It makes for some very useful and easy error logging, especially when the logging takes place far up the execution chain from where the error happened. This is easily possible with a custom error type and some log functions. I have published on GitHub my small and crude implementation that I use in a few hobby projects, MIT licensed, if anyone is interested. https://github.com/sveinnthorarins/sterlo |
|
https://github.com/Danlock/pkg/blob/main/errors/attr_test.go
I can understand why it's not in the stdlib though, it seems easy enough to run into key overwriting issues if a dependency returned custom errors with attributes.
I appreciate the built in support slog has for slog.GroupValue and the slog.LogValuer interface that enables everyone to build a solution best for their needs.