structlog-pretty

raw JSON →
0.4.3 verified Sat May 09 auth: no python

A collection of structlog processors to produce prettier log output, including syntax highlighting, numeric rounding, and key-value formatting. Current version 0.4.3, maintained but low release cadence.

pip install structlog-pretty
error AttributeError: module 'structlog_pretty' has no attribute 'NumericRounder'
cause Importing from wrong module – should be structlog_pretty.processors.
fix
Use: from structlog_pretty.processors import NumericRounder
error ValueError: cannot convert float NaN to integer
cause NumericRounder encountered NaN value; older versions had this bug if decimal places set incorrectly.
fix
Ensure value is not NaN or upgrade to latest version.
breaking NumericRounder may convert boolean values to floats (0.0/1.0) unless you upgrade to v0.1.1 or later. Always use >=0.1.1.
fix Upgrade: pip install structlog-pretty>=0.1.1
gotcha SyntaxHighlighter requires Pygments to be installed; otherwise it silently falls back to plain text. No error is raised.
fix Install Pygments: pip install pygments
gotcha Trailing whitespace in log messages is preserved, which can cause unexpected line breaks if not intended.
fix Strip trailing whitespace manually if needed.

Basic configuration with NumericRounder and KeyValueFormatter.

import structlog
from structlog_pretty.processors import NumericRounder, KeyValueFormatter

structlog.configure(
    processors=[
        structlog.stdlib.add_log_level,
        structlog.processors.TimeStamper(fmt="iso"),
        NumericRounder(),
        KeyValueFormatter(),
        structlog.dev.ConsoleRenderer()
    ],
    context_class=dict,
    wrapper_class=structlog.stdlib.BoundLogger,
    cache_logger_on_first_use=True,
)
log = structlog.get_logger()
log.info("Logging with style", count=1234.5678, user="alice")