paper-dynasty-card-creation/exceptions.py
Cal Corum 0a17745389 Run black and ruff across entire codebase
Standardize formatting with black and apply ruff auto-fixes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-08 14:24:33 -05:00

32 lines
896 B
Python

import logging
from logging.handlers import RotatingFileHandler
from typing import Literal
logger = logging.getLogger("card_creation")
logger.setLevel(logging.INFO)
handler = RotatingFileHandler(
filename="logs/card_creation.log",
# encoding='utf-8',
maxBytes=32 * 1024 * 1024, # 32 MiB
backupCount=5, # Rotate through 5 files
)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
def log_exception(
e: Exception,
msg: str = "",
level: Literal["debug", "error", "info", "warn"] = "error",
):
if level == "debug":
logger.debug(msg, stack_info=True)
elif level == "error":
logger.error(msg, stack_info=True)
elif level == "info":
logger.info(msg, stack_info=True)
else:
logger.warning(msg, stack_info=True)
raise e(msg)