Mondrian configures the python standard logging module with reasonable defaults, and enhance its default output formatters for better readability.
Mondrian is a small library that will make you use python
logging
module, once and for all.Most python coders who avoids the systematic usage of
logging
in their projects does so because it feels complicated to setup, but it's not.Mondrian provides a one-call interface to its configuration, with pretty formatters that makes you feel great.
Install the mondrian
package:
$ pip install mondrian
In your project's entrypoints (for example, <yourpackage>/__main__.py
, call
mondrian.setup()
:
import mondrian
import logging
logger = logging.getLogger()
def main():
...
logger.info('Hello')
...
if __name__ == '__main__':
mondrian.setup(excepthook=True)
logger.setLevel(logging.INFO)
main()
You can remove the excepthook=True
if you don't want mondrian to override the default exception
handler for better formating. But it's nice, try it first.
Now, use python's logging
module in your project's files:
import logging
logger = logging.getLogger(__name__)
def some_very_nice_function():
...
logger.warning('Ola amigo!')
...
That's all, folks!
Mondrian and the surrounding material (like this website) is licensed under the Apache License, version 2.0.