Skip to content

Add logging to centralized checks #42741

@scbedd

Description

@scbedd

But when we add this logging, we need to do all of the stuff we didn't do when originally using logging library.

  • Central logging configuration which honors CLI args --quiet (ERROR) --verbose (DEBUG)
  • Central logging configuration which, if no CLI args, also honors CLI variable LOG_LEVEL. Possible values:
    • DEBUG
    • INFO
    • WARNING
    • ERROR
    • CRITICAL

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()
...

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions