Skip to content

sgn.logger

Logging utilities and configuration for SGN.

configure_sgn_logging()

Configure SGN logging with handlers and environment-based levels.

Environment Variables

SGNLOGLEVEL: Space-separated list of logger configurations in format: - "LEVEL" (applies to the main logger) - "logger_name:LEVEL" (applies to specific child logger)

Examples:

SGNLOGLEVEL="DEBUG" -> Sets main logger to DEBUG level SGNLOGLEVEL="pipeline:INFO subprocess:WARNING" -> Sets specific loggers

Source code in src/sgn/logger.py
def configure_sgn_logging():
    """Configure SGN logging with handlers and environment-based levels.

    Environment Variables:
        SGNLOGLEVEL: Space-separated list of logger configurations in format:
                    - "LEVEL" (applies to the main logger)
                    - "logger_name:LEVEL" (applies to specific child logger)

    Examples:
        SGNLOGLEVEL="DEBUG" -> Sets main logger to DEBUG level
        SGNLOGLEVEL="pipeline:INFO subprocess:WARNING" -> Sets specific loggers
    """
    # Set up the root SGN logger
    sgn_logger = logging.getLogger("sgn")

    # Add StreamHandler if not already present
    if not sgn_logger.handlers:
        handler = logging.StreamHandler()
        sgn_logger.addHandler(handler)

    # Parse environment variable for log level configuration
    if SGN_LOG_LEVEL_VAR in os.environ:
        config_levels = _parse_log_level_config(
            os.environ[SGN_LOG_LEVEL_VAR], "sgn", SGN_LOG_LEVELS
        )
        _apply_log_levels(sgn_logger, "sgn", config_levels, SGN_LOG_LEVELS)

setup_custom_levels()

Set up SGN's custom logging levels.

This function registers custom logging levels like MEMPROF with Python's logging system. This function is idempotent - safe to call multiple times.

Source code in src/sgn/logger.py
def setup_custom_levels():
    """Set up SGN's custom logging levels.

    This function registers custom logging levels like MEMPROF with Python's
    logging system. This function is idempotent - safe to call multiple times.
    """
    _add_logging_level("MEMPROF", SGN_LOG_LEVELS["MEMPROF"], "memprofile")