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
New feature to allow adding extra information to log
- ### Context
It's quite common to add extra info to each log messages to make
debugging easier.
For instance, adding a request ID to trace the request more easily
if an exception occurs. Or add user information for various needs.
Right now, the easiest way to implement this is to create a custom
formatter.
### Problem
I believe formatting the log and adding extra information are two
distincts features that should be handled with different objects.
Moreover, because libraries or frameworks usually provide this
feature, it makes things hard for them to not conflict with
each others. As well as conflicting with the potential
formatter set by an application.
It ends up in a cascade of monkeypatch and doesn't allow
much flexibility for the end user.
### Solution
I'd like to introduce the concept of a log processor who's interface
is similar to the formatter but its responsibility is to only
add extra info to the message.
More importantly, a logger can have multiple processors, each
defining the logic within their scope.
This should allow for a lot more flexibility (applications can
now easily re-order processors, remove or add them on the fly,
change their formatter afterward without breaking libraries
functionalities).
It will also make things easier for libraries and provide a cleaner
way to hook into the logger.
This change is fully backward compatible.
0 commit comments