setup_logging (ductor_bot/logging_config.py)

ductor · ductor_bot/logging_config.py · python · MIT
infra, tag:knn-classified

Centralized logging setup with console, rotating file, and color support for Python apps.

# Source: https://github.com/PleasePrompto/ductor | License: MIT | Copyright 2025-2026 PleasePrompto
# Provided via justclaw.it.com; keep this notice with the code.
"""Centralized logging setup: console (colored) + rotating file.

Call ``setup_logging()`` once at startup.  All modules use ``logging.getLogger(__name__)``.
"""

from __future__ import annotations

import atexit
import logging
import queue
import sys
from logging.handlers import QueueHandler, QueueListener, RotatingFileHandler
from pathlib import Path

MAX_BYTES = 5 * 1024 * 1024  # 5 MB per file
BACKUP_COUNT = 3

CONSOLE_FMT = "%(asctime)s %(levelname)s %(name)s: %(ctx)s%(message)s"
FILE_FMT = "%(asctime)s [%(levelname)s] %(name)s:%(filename)s:%(lineno)d: %(ctx)s%(message)s"
DATE_FMT = "%H:%M:%S"
FILE_DATE_FMT = "%Y-%m-%d %H:

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key