-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Open
Labels
type/proposalThe new feature has not been accepted yet but needs to be discussed first.The new feature has not been accepted yet but needs to be discussed first.
Description
Feature Description
if accepted supersedes: #21758
filing as separate proposal due to a slightly different scope with the same outcome and names specific provider instead of just outcome.
With the introduction of go 1.21 log/slog was added to standard library. It's a structured logging library that allows to log a message with a key-value pairs added to it for later processing. It provides two formatted loggers (plus built-in default) json and logfmt
Why slog instead of zerolog or zap? It's in the standard library. I don't have a strong reason for/against alternative libraries.
As for why I feel it's worth migrating:
Benefits
- It is very helpful when making statistics from logs with tools like angle-grinder, loki and similar tools
- It's easier to filter through logs as you can set more complex filters to narrow the search down to specific context or exclude noise instead of just grepping through (though that doesn't go away).
- Easy to include and find context for the log, for example when logging error in caused by a user, userid can be added as an attribute to look for later, which could be helpful for abuse detection via logs.
- Third party extensions (such as sampling or some specific sinks) are available.
- Specific loggers can write to the same file separated with an attribute
Drawbacks
- Requires modifying all log lines in current codebase from printf to structured. For the switch current logs could format the message with sprintf so the change wouldn't have to be done in one go but in chunks.
- I believe support for adding, pausing and removing loggers would require custom handler or io.Writer.
- It's a breaking change unless a custom handler to print old style is added.
- Access logs might be an issue to port (if they would be ported to this at all).
Screenshots
No response
lunny, splitt3r and silverwind
Metadata
Metadata
Assignees
Labels
type/proposalThe new feature has not been accepted yet but needs to be discussed first.The new feature has not been accepted yet but needs to be discussed first.