dr-severity-grading / src /utils /logging_utils.py
mshaiel2004's picture
Upload folder using huggingface_hub
78856c0 verified
Raw History Blame Contribute Delete
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)