Spaces:
Runtime error
Runtime error
Download src/utils/logging_utils.py from mshaiel2004/dr-severity-grading: direct link, hf CLI and curl.
- Browser
- Download file 939 Bytes
-
https://huggingface.co/spaces/mshaiel2004/dr-severity-grading/resolve/main/src/utils/logging_utils.py
- Command line
-
hf download hf://spaces/mshaiel2004/dr-severity-grading/src/utils/logging_utils.py
-
curl -L -o logging_utils.py https://huggingface.co/spaces/mshaiel2004/dr-severity-grading/resolve/main/src/utils/logging_utils.py
939 Bytes
| import logging | |
| import sys | |
| from typing import Optional | |
| def setup_logging( | |
| level: int = logging.INFO, | |
| log_file: Optional[str] = None, | |
| ) -> None: | |
| """Configure root logger with clean formatting. | |
| Args: | |
| level: Logging level (e.g. logging.INFO). | |
| log_file: Optional path to output log file. | |
| """ | |
| formatter = logging.Formatter( | |
| fmt="%(asctime)s [%(levelname)s] (%(name)s) %(message)s", | |
| datefmt="%Y-%m-%d %H:%M:%S", | |
| ) | |
| handlers = [logging.StreamHandler(sys.stdout)] | |
| if log_file: | |
| handlers.append(logging.FileHandler(log_file)) | |
| logging.basicConfig( | |
| level=level, | |
| format="%(asctime)s [%(levelname)s] (%(name)s) %(message)s", | |
| datefmt="%Y-%m-%d %H:%M:%S", | |
| handlers=handlers, | |
| force=True, | |
| ) | |
| def get_logger(name: str) -> logging.Logger: | |
| """Get a logger instance with the specified name.""" | |
| return logging.getLogger(name) | |