logger icon indicating copy to clipboard operation
logger copied to clipboard

New feature to allow adding extra information to log

Open Edouard-chin opened this issue 1 year ago • 0 comments

Hello, thank you for maintaining this library ❤️ ! I'm opening this PR to propose a new feature:

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.

Edouard-chin avatar Jul 05 '23 17:07 Edouard-chin