DEV Community

TildAlice
TildAlice

Posted on • Originally published at tildalice.io

logging vs loguru vs structlog: Speed & API Benchmarks

The stdlib logging Module Wins on Raw Throughput

Python's built-in logging module beats both loguru and structlog in pure write speed — but that's almost never the metric that matters in production. I spent a weekend benchmarking all three libraries with realistic payloads (structured JSON, exception formatting, context injection) and the performance story is more nuanced than "stdlib = fast."

The real question isn't throughput. It's how much time you spend wrestling with Logger.getLogger(__name__), formatters, handlers, and handler-level filters versus just writing logger.info("message", user_id=123) and shipping.

Close-up view of marked timber logs stacked outdoors, ideal for forestry and natural resource themes.

Photo by Roman Biernacki on Pexels

Benchmark Setup: What I Actually Measured

I tested on Python 3.11 with three scenarios:

  1. Simple string logging — 100k iterations of logger.info("hello world")
  2. Structured context — 100k iterations with 5 key-value pairs per log
  3. Exception formatting — 10k iterations with traceback serialization

Continue reading the full article on TildAlice

Top comments (0)