But when we add this logging, we need to do all of the stuff we didn't do when originally using logging library.
Code proposal
# ci_tools/logging.py
logger = logging.getLogger("azure-sdk-tools")
def configure_logging(
level: str = "INFO",
fmt: str = "%(asctime)s [%(levelname)s] %(name)s: %(message)s"
) -> None:
"""
Configures the shared logger. Should be called **once** at startup.
"""
numeric_level = getattr(logging, level.upper(), None)
# parse cli arg, and compare to numeric level?
# parse LOG_LEVEL environment variable
if not isinstance(numeric_level, int):
raise ValueError(f"Invalid log level: {level}")
logger.setLevel(numeric_level)
# Propagate logger config globally if needed
logging.basicConfig(level=numeric_level)
# azpysdk/main.py
from ci_tools.logging import logger
# ...main code after parse args
parse common CLI arg for --quiet or --verbose
configure_logging(args.level)
and anywhere else we need it
from ci_tools.logging import logger
logger.info()
logger.critical()
...
But when we add this logging, we need to do all of the stuff we didn't do when originally using
logginglibrary.LOG_LEVEL. Possible values:Code proposal
and anywhere else we need it