Simple, sane, and sensible Logging in Python
TLDR
If you’re not already using it, there’s a simple, powerful wrapper around Python’s Logging module called log2d that gives you access to all sorts of advanced features using a deceptively simple syntax. It’s literally all you need if you’re in the 80% of Developers who just want to adopt good logging practices quickly, using sensible default settings, without having to learn yet another peculiar syntax, and without having to store away long snippets of boiler-plate code which are too convoluted to be memorable.
Just install it in the usual way e.g.
python -m pip install log2d
Then head over to the README file on Github. It’s easy enough to follow, so this article won’t repeat how to use log2d, but if you’re unsure why log2d should become your new best friend, please read on…
Why Log instead of print( )?
Learning Python’s logging module and weaning yourself off print() statements is considered by many people to be an important milestone in the journey from Python novice to “Pythonista”. It’s better than print() for several reasons, but most importantly:
- You can track (and later analyse) the timing of every message.
- You can output in a standardised format which…