Spaces:
Sleeping
Sleeping
File size: 860 Bytes
8ed954c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import logging
import sys
_configured = False
def get_logger(name: str = "primogreedy") -> logging.Logger:
"""Return a named logger with consistent formatting.
All PrimoGreedy modules should call ``get_logger(__name__)`` to get a
logger scoped to their module. The root ``primogreedy`` logger is
configured once with a StreamHandler so every child inherits it.
"""
global _configured
root = logging.getLogger("primogreedy")
if not _configured:
root.setLevel(logging.INFO)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(
logging.Formatter(
"%(asctime)s | %(name)s | %(levelname)s | %(message)s",
datefmt="%H:%M:%S",
)
)
root.addHandler(handler)
_configured = True
return logging.getLogger(name)
|