Simple, sane, and sensible Logging in Python

Pete Fison
PythonIQ
Published in
4 min readSep 30, 2022

--

Screenshot by author using VS Code, One Monokai theme and CodeSnap extension.

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…

--

--

PythonIQ
PythonIQ

Published in PythonIQ

Take your Python coding to the next level and learn from others with these practical, thought-provoking, and insightful articles. We’re all about programming in Python.

Pete Fison
Pete Fison

Written by Pete Fison

Experienced Python developer with a special interest in web scraping, data wrangling, ETL, NLP, and AI Prompt Engineering. Former IT Director & Video Producer.

Responses (4)