by connorbrinton · 4y ago · 0 comments
One of my favorite features of loguru is the ability to contextualize logging messages using a context manager.
with logger.contextualize(user_name=user_name):
handle_request(...)
Within the context manager, all loguru logging messages include the contextual information. This is especially nice when used in combination with loguru's native JSON formatting support and a JSON-compatible log archiving system.One downside of loguru is that it doesn't include messages from Python's standard logging system, but it can be integrated as a logging handler for the standard logging system. At the company where I work we've created a helper similar to Datadog's ddtrace-run executable to automatically set up these integrations and log message formatting with loguru
I'll never go back to that rancid pile of shit that is the builtin logger lib.
This is the standard approach to produce a log:
```from loguru import logger logger.info("hello world") ```
But betteid avise you to research more, because the library is nice to use and is well documented.