deepvision-prompt-builder / core /logging_config.py
Salman Abjam
Initial deployment: DeepVision Prompt Builder v0.1.0
eb5a9e1
"""
Logging Configuration
Setup logging for DeepVision using loguru.
"""
import sys
from pathlib import Path
from loguru import logger
from core.config import config
def setup_logging(
log_level: str = "INFO",
log_file: Path = None,
rotation: str = "10 MB",
retention: str = "1 week"
) -> None:
"""
Setup logging configuration.
Args:
log_level: Logging level (DEBUG, INFO, WARNING, ERROR)
log_file: Path to log file (None for no file logging)
rotation: Log rotation size/time
retention: How long to keep old logs
"""
# Remove default handler
logger.remove()
# Console handler
logger.add(
sys.stderr,
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | "
"<level>{level: <8}</level> | "
"<cyan>{name}</cyan>:<cyan>{function}</cyan> - "
"<level>{message}</level>",
level=log_level,
colorize=True,
)
# File handler (if specified)
if log_file:
log_file = Path(log_file)
log_file.parent.mkdir(parents=True, exist_ok=True)
logger.add(
log_file,
format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | "
"{name}:{function} - {message}",
level=log_level,
rotation=rotation,
retention=retention,
compression="zip",
)
logger.info(f"Logging configured - Level: {log_level}")
# Auto-configure if imported
if config.DEBUG:
setup_logging(
log_level="DEBUG",
log_file=config.BASE_DIR / "logs" / "deepvision.log"
)
else:
setup_logging(
log_level="INFO",
log_file=config.BASE_DIR / "logs" / "deepvision.log"
)