5 ms·
Another great project for Python logging is loguru: https://loguru.readthedocs.io/en/stable/overview.html https://loguru.readthedocs.io/en/stable/overview.html
by connorbrinton 4y ago
Another great project for Python logging is loguru:
https://loguru.readthedocs.io/en/stable/overview.html https://loguru.readthedocs.io/en/stable/overview.html
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
- isoprophlex 4y agoCannot recommend loguru highly enough. After a coworker showed it to me, I fell in love immediately. I'll never go back to that rancid pile of shit that is the builtin logger lib.
- codethief 4y agoDoes loguru come with a lot of global state like the standard logging library? In my experience this makes logging a real PITA when forking multiple processes…
- pnt12 4y agoI think it may even have more global state than standard logging. 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.
- codethief 4y agoThanks, I'll have a look then!
- sigzero 4y agoWow, reading the docs and loguru looks great.