Skip to content

Logging

Centralized logging configuration for the Inference SDK.

get_logger(module_name)

Get a logger for the specified module.

Automatically configures basic logging on first use if no handlers exist.

Parameters:

Name Type Description Default
module_name str

Name of the module requesting the logger.

required

Returns:

Type Description
Logger

logging.Logger: Configured logger for the module.

Source code in inference_sdk/utils/logging.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
def get_logger(module_name: str) -> logging.Logger:
    """Get a logger for the specified module.

    Automatically configures basic logging on first use if no handlers exist.

    Args:
        module_name: Name of the module requesting the logger.

    Returns:
        logging.Logger: Configured logger for the module.
    """
    global _configured

    sdk_logger = logging.getLogger(SDK_LOGGER_NAME)

    # Configure basic logging on first use if needed
    if not _configured and not sdk_logger.handlers:
        handler = logging.StreamHandler(sys.stderr)
        handler.setFormatter(logging.Formatter("%(levelname)s [%(name)s] %(message)s"))
        sdk_logger.addHandler(handler)
        sdk_logger.setLevel(logging.INFO)
        sdk_logger.propagate = False
        _configured = True

    return logging.getLogger(f"{SDK_LOGGER_NAME}.{module_name}")