app.infra.logging_setup

Minimal stdlib-only logging setup with console and JSON file output.

ConsoleFormatter

Bases: Formatter

Single-line console formatter: YYYY-MM-DD HH:MM:SS | LEVEL | logger.name | message

JSONFormatter

Bases: Formatter

JSON formatter with fields: ts, level, logger, message, pathname, lineno, funcName, process, threadName

get_logger(name=__name__)

Get a logger instance

init_logging(level='INFO', log_dir='logs', log_file='app.log', rotate_max_bytes=10 * 1024 * 1024, rotate_backups=5, ecs_compatible=False)

Initialize logging with console and rotating file handlers (idempotent).

Parameters:
  • level (str, default: 'INFO' ) –

    Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)

  • log_dir (str, default: 'logs' ) –

    Directory for log files

  • log_file (str, default: 'app.log' ) –

    Log file name

  • rotate_max_bytes (int, default: 10 * 1024 * 1024 ) –

    Max bytes per log file before rotation

  • rotate_backups (int, default: 5 ) –

    Number of backup files to keep

  • ecs_compatible (bool, default: False ) –

    If True, use ECS-compatible JSON field names