"""
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="{time:YYYY-MM-DD HH:mm:ss} | "
"{level: <8} | "
"{name}:{function} - "
"{message}",
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"
)