Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Another great project for Python logging is loguru: 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



Cannot 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.


Does 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…


I 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.


Thanks, I'll have a look then!


Wow, reading the docs and loguru looks great.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: