Download src/utils/logging.py from MHamdan/SPARKNET: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/spaces/MHamdan/SPARKNET/resolve/76c3b0a8cd44eb930c2ad41fc0e95acdb3cd2bab/src/utils/logging.py
- Command line
-
hf download hf://spaces/MHamdan/SPARKNET@76c3b0a8cd44eb930c2ad41fc0e95acdb3cd2bab/src/utils/logging.py
-
curl -L -o logging.py https://huggingface.co/spaces/MHamdan/SPARKNET/resolve/76c3b0a8cd44eb930c2ad41fc0e95acdb3cd2bab/src/utils/logging.py
1.77 kB
| """ | |
| Logging configuration for SPARKNET | |
| Provides structured logging with multiple outputs | |
| """ | |
| import sys | |
| from pathlib import Path | |
| from loguru import logger | |
| from typing import Optional | |
| def setup_logging( | |
| log_level: str = "INFO", | |
| log_file: Optional[str] = None, | |
| rotation: str = "100 MB", | |
| retention: str = "7 days", | |
| colorize: bool = True, | |
| ): | |
| """ | |
| Configure logging for SPARKNET. | |
| Args: | |
| log_level: Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) | |
| log_file: Path to log file or None for no file logging | |
| rotation: Log rotation size | |
| retention: Log retention period | |
| colorize: Enable colored output | |
| """ | |
| # Remove default logger | |
| logger.remove() | |
| # Add 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>:<cyan>{line}</cyan> - <level>{message}</level>", | |
| level=log_level, | |
| colorize=colorize, | |
| ) | |
| # Add file handler if specified | |
| if log_file: | |
| log_path = Path(log_file) | |
| log_path.parent.mkdir(parents=True, exist_ok=True) | |
| logger.add( | |
| log_file, | |
| format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name}:{function}:{line} - {message}", | |
| level=log_level, | |
| rotation=rotation, | |
| retention=retention, | |
| compression="zip", | |
| ) | |
| logger.info(f"Logging to file: {log_file}") | |
| logger.info(f"Logging initialized at {log_level} level") | |
| def get_logger(name: str): | |
| """ | |
| Get a logger instance for a specific module. | |
| Args: | |
| name: Module name | |
| Returns: | |
| Logger instance | |
| """ | |
| return logger.bind(name=name) | |