Skip to content

Register now for

# Reference for `hub_sdk/helpers/logger.py`

Note

This file is available at https://github.com/ultralytics/hub-sdk/blob/main/hub_sdk/helpers/logger.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!

## `` hub_sdk.helpers.logger.Logger

    Logger(logger_name=None, log_format=None, log_level=None)

Represents a logger configuration for handling log messages.

Attributes:

Name | Type | Description
--- | --- | ---
`logger_name` | `str` | Name of the logger. Defaults to the name of the calling module.
`log_format` | `str` | Format for log messages. Defaults to the value of 'LOGGER_FORMAT' environment variable or '%(asctime)s - %(name)s - %(levelname)s - %(message)s'.
`log_level` | `str` | Log level for the logger. Defaults to the value of 'LOGGER_LEVEL' environment variable or 'INFO'.
`logger` | `Logger` | The configured logger instance.

Parameters:

Name | Type | Description | Default
--- | --- | --- | ---
`logger_name` | `str` | Name of the logger. If not provided, defaults to the root logger. | `None`
`log_format` | `str` | Format for log messages. Defaults to the value of 'LOGGER_FORMAT' environment variable or '%(asctime)s - %(name)s - %(levelname)s - %(message)s'. | `None`
`log_level` | `str` | Log level for the logger. Defaults to the value of 'LOGGER_LEVEL' environment variable or 'INFO'. | `None`

Source code in `hub_sdk/helpers/logger.py`

    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    def __init__(self, logger_name=None, log_format=None, log_level=None):
        """
        Initialize a Logger instance.

        Args:
            logger_name (str, optional): Name of the logger. If not provided, defaults to the root logger.
            log_format (str, optional): Format for log messages. Defaults to the value of 'LOGGER_FORMAT'
                                        environment variable or '%(asctime)s - %(name)s - %(levelname)s - %(message)s'.
            log_level (str, optional): Log level for the logger. Defaults to the value of 'LOGGER_LEVEL'
                                       environment variable or 'INFO'.
        """
        self.log_format = log_format or os.environ.get(
            "LOGGER_FORMAT", "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
        )
        self.log_level = log_level or os.environ.get("LOGGER_LEVEL", "INFO")
        self.logger_name = logger_name or __name__

        self.logger = self._configure_logger()

### `` get_logger

    get_logger() -> logging.Logger

Get the configured logger instance.

Returns:

Type | Description
--- | ---
`Logger` | The configured logger instance.

Source code in `hub_sdk/helpers/logger.py`

    57
    58
    59
    60
    61
    62
    63
    64
    def get_logger(self) -> logging.Logger:
        """
        Get the configured logger instance.

        Returns:
            (logging.Logger): The configured logger instance.
        """
        return self.logger

📅 Created 1 year ago ✏️ Updated 1 month ago