Spaces:
Paused
Paused
Download api/utils/logging.py from mrqadeer/email-classifier: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/mrqadeer/email-classifier/resolve/main/api/utils/logging.py
- Command line
-
hf download hf://spaces/mrqadeer/email-classifier/api/utils/logging.py
-
curl -L -o logging.py https://huggingface.co/spaces/mrqadeer/email-classifier/resolve/main/api/utils/logging.py
1.18 kB
| import sys | |
| from loguru import logger | |
| import time | |
| from pathlib import Path | |
| def setup_api_logging(log_path: Path ): | |
| """ | |
| Configure Loguru logger for the API | |
| Args: | |
| log_path: Optional path to store log files | |
| """ | |
| # Remove default handler | |
| logger.remove() | |
| # Add stdout handler with custom format | |
| logger.add( | |
| sys.stdout, | |
| colorize=True, | |
| format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>", | |
| level="INFO" | |
| ) | |
| # Add file logging if path provided | |
| if log_path: | |
| log_path.parent.mkdir(parents=True, exist_ok=True) | |
| logger.add( | |
| log_path / f"api_{time.strftime('%Y%m%d')}.log", | |
| rotation="00:00", # New file at midnight | |
| compression="zip", # Compress old logs | |
| retention="30 days", # Keep logs for 30 days | |
| format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name}:{function}:{line} - {message}", | |
| level="DEBUG" | |
| ) | |
| logger.info("API logging configured") | |
| return logger | |