""" Logging setup and log reading. LIM previously configured no logging at all, which left Flask's logger at WARNING and wrote nothing to disk — so a quiet background feature like the instruction fetcher had no trail to follow. This attaches a rotating file handler to the root logger, so every module logger (app.services.*, and the fetcher in particular) lands in one file, and provides the parsing the admin log viewer needs. Rotation is by size, not date: LOG_MAX_BYTES per file, LOG_BACKUP_COUNT old copies, so disk use is bounded no matter how chatty things get. Created by: Jess Rogerson (yelling commands at Claude.AI) """ import io import logging import os import re from logging.handlers import RotatingFileHandler LOG_FILENAME = 'lim.log' LEVELS = ('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL') LEVEL_BADGES = { 'DEBUG': 'secondary', 'INFO': 'info', 'WARNING': 'warning', 'ERROR': 'danger', 'CRITICAL': 'danger', } # 2026-09-26 13:38:00 INFO app.services.instruction_fetcher | message LINE_RE = re.compile( r'^(?P