You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think the log/slog API has a gap in the purely attribute based functions/methods, and adding WithAttrs to the package scope and to Logger would fill this gap. I would also find this useful, I would like to enforce/lint that our logging only uses attribute based logging functionality to avoid potential issues with missing values for keys when using the more general functionality, but it's difficult to do right now since WithAttrs is missing on Logger.
Our logging behavior typically looks something like this:
If the only concern is enforcement, it should be straightforward to write a vet check (static analyzer) that checks that all calls to Logger.With take Attrs.
Look for a method on *slog.Logger named With. This code looks for a top-level function with a given name; you would have to adapt it slightly to look for a method. I would browse go/analysis/passes for code that does that already.
Check that the type of each argument is slog.Attr.
You can make that into a standalone CLI tool with one line of code (example).
Proposal Details
I think the
log/slog
API has a gap in the purely attribute based functions/methods, and addingWithAttrs
to the package scope and toLogger
would fill this gap. I would also find this useful, I would like to enforce/lint that our logging only uses attribute based logging functionality to avoid potential issues with missing values for keys when using the more general functionality, but it's difficult to do right now sinceWithAttrs
is missing onLogger
.Our logging behavior typically looks something like this:
Ideally I'd like us to be able to do the following:
The text was updated successfully, but these errors were encountered: