Multiline Log Formatter

raw JSON →
0.1.8 verified Mon Apr 27 auth: no python

A Python logging formatter that prefixes multiline log messages and tracebacks with the log level, ensuring uniform indentation for multi-line output. Current version 0.1.8. Low release cadence; last update 2022.

pip install multiline-log-formatter
error ModuleNotFoundError: No module named 'multiline-log-formatter'
cause Trying to import the package with hyphens instead of underscores.
fix
Use: from multiline_log_formatter import MultilineLogFormatter
error AttributeError: module 'multiline_log_formatter' has no attribute 'MultilineLogFormatter'
cause Incorrect import spelling or case.
fix
Use: from multiline_log_formatter import MultilineLogFormatter (note capital letters)
gotcha The formatter does not prefix continuation lines of a multiline message with the log level; it only indents them. The prefix appears only on the first line.
fix Check if the output meets your expectations; consider using a custom formatter if you need each line prefixed.
gotcha The package name in pip uses hyphens (multiline-log-formatter), but the Python import uses underscores (multiline_log_formatter).
fix Import using underscores.
deprecated No known deprecations. The package has not been updated since 2022.
fix None.

Basic usage with StreamHandler and exception logging.

import logging
from multiline_log_formatter import MultilineLogFormatter

logger = logging.getLogger(__name__)
handler = logging.StreamHandler()
formatter = MultilineLogFormatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
logger.setLevel(logging.DEBUG)

logger.info('Single line message')
try:
    1/0
except:
    logger.exception('An error occurred')