Technical
The Python Logging Config I Stopped Changing
Python's logging module is famously painful to configure. I used to rewrite the config for every project, convinced the last one wasn't quite right. In August I forced myself to pick a config and not touch it. A month later, no service has needed a change. The config was never the problem. My restlessness was.
The Config That Stuck
import logging
import sys
def setup_logging(level=logging.INFO):
root = logging.getLogger()
root.setLevel(level)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s %(name)s %(message)s'
))
root.handlers = [handler]
logging.getLogger('urllib3').setLevel(logging.WARNING)Twelve lines. It logs everything to stdout in a grep-friendly format, mutes the one library that spams INFO logs, and runs in every service I ship.
Why This One Works
Three rules behind the config:
- Stdout only. Let the platform handle persistence.
- Flat format. Don't fight the default formatter.
- Mute known noise explicitly. Don't filter creatively.
The Meta-Lesson
The thing I learned here wasn't about logging. It was about infrastructure restlessness. Tweaking configs that already work feels productive. It isn't. Pick a config, commit, move on to work that compounds.
See the Python logging cookbook if you want more patterns.
RELATED READING
The Consulting Shift I Am Making In Year Two
After a year of writing and building, my consulting practice is changing shape. Shorter engagements. Sharper outcomes.
ReadThe Frontend Shift: Shipping Less JavaScript In Year Two
A year ago I reached for Next.js for everything. This year I often reach for nothing.
ReadThe Serverless Lesson I Would Write On A Sticky Note
After a year of shipping serverless projects, one rule explains most of the wins and all of the losses.
Read