Files
nexus-claude-api/src/nexus_claude_api/logging_config.py

27 lines
795 B
Python
Raw Normal View History

from __future__ import annotations
import logging
from pathlib import Path
LOG_DIR = Path("logs")
LOG_FILE = LOG_DIR / "nexus-claude-api.log"
LOG_FORMAT = "%(asctime)s %(levelname)s %(name)s: %(message)s"
def configure_logging(*, verbose: bool = False, log_file: Path = LOG_FILE) -> Path:
log_file.parent.mkdir(parents=True, exist_ok=True)
formatter = logging.Formatter(LOG_FORMAT)
file_handler = logging.FileHandler(log_file, encoding="utf-8")
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
app_logger = logging.getLogger("nexus_claude_api")
app_logger.handlers.clear()
app_logger.setLevel(logging.DEBUG if verbose else logging.INFO)
app_logger.addHandler(file_handler)
app_logger.propagate = False
return log_file