์ฝ˜ํ…์ธ ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

์ฐธ์กฐ hub_sdk/helpers/logger.py

์ฐธ๊ณ 

์ด ํŒŒ์ผ์€ https://github.com/ultralytics/ hub-sdk/blob/main/ hub_sdk/helpers/logger .py์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌธ์ œ๋ฅผ ๋ฐœ๊ฒฌํ•˜๋ฉด ํ’€ ๋ฆฌํ€˜์ŠคํŠธ (๐Ÿ› ๏ธ)๋ฅผ ์ œ์ถœํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ฃผ์„ธ์š”. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค ๐Ÿ™!



hub_sdk.helpers.logger.Logger

๋กœ๊ทธ ๋ฉ”์‹œ์ง€ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•œ ๋กœ๊ฑฐ ๊ตฌ์„ฑ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

์†์„ฑ:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช…
logger_name str

๋กœ๊ฑฐ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ ํ˜ธ์ถœ ๋ชจ๋“ˆ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค.

log_format str

๋กœ๊ทธ ๋ฉ”์‹œ์ง€์˜ ํ˜•์‹์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ 'LOGGER_FORMAT' ํ™˜๊ฒฝ ๋ณ€์ˆ˜์˜ ๊ฐ’ ๋˜๋Š” '%(์‹œ๊ฐ„)-%(์ด๋ฆ„)-%(์ˆ˜์ค€๋ช…)-%(๋ฉ”์‹œ์ง€)-%(๋ฉ”์‹œ์ง€)'์ž…๋‹ˆ๋‹ค.

log_level str

๋กœ๊ฑฐ์˜ ๋กœ๊ทธ ๋ ˆ๋ฒจ์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ 'LOGGER_LEVEL' ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๋˜๋Š” 'INFO'์˜ ๊ฐ’์ž…๋‹ˆ๋‹ค.

logger Logger

๊ตฌ์„ฑ๋œ ๋กœ๊ฑฐ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ hub_sdk/helpers/logger.py
class Logger:
    """
    Represents a logger configuration for handling log messages.

    Attributes:
        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 (logging.Logger): The configured logger instance.
    """

    def __init__(self, logger_name=None, log_format=None, log_level=None):
        """
        Initialize a Logger instance.

        Args:
            logger_name (str): Name of the logger. If not provided, defaults to the root logger.
            log_format (str): Format for log messages. Defaults to the value of 'LOGGER_FORMAT'
                             environment variable or '%(asctime)s - %(levelname)s - %(message)s'.
            log_level (str): 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()

    def _configure_logger(self) -> logging.Logger:
        """
        Configure the logger with the provided settings.

        Returns:
            (logging.Logger): A configured logger instance.
        """
        logger = logging.getLogger(self.logger_name)
        logger.setLevel(self.log_level)

        formatter = logging.Formatter(self.log_format)

        handler = logging.StreamHandler()
        handler.setFormatter(formatter)

        logger.addHandler(handler)
        return logger

    def get_logger(self) -> logging.Logger:
        """
        Get the configured logger instance.

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

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

๋กœ๊ฑฐ ์ธ์Šคํ„ด์Šค๋ฅผ ์ดˆ๊ธฐํ™”ํ•ฉ๋‹ˆ๋‹ค.

๋งค๊ฐœ๋ณ€์ˆ˜:

์ด๋ฆ„ ์œ ํ˜• ์„ค๋ช… ๊ธฐ๋ณธ๊ฐ’
logger_name str

๋กœ๊ฑฐ์˜ ์ด๋ฆ„์ž…๋‹ˆ๋‹ค. ์ œ๊ณตํ•˜์ง€ ์•Š์œผ๋ฉด ๊ธฐ๋ณธ๊ฐ’์€ ๋ฃจํŠธ ๋กœ๊ฑฐ์ž…๋‹ˆ๋‹ค.

None
log_format str

๋กœ๊ทธ ๋ฉ”์‹œ์ง€์˜ ํ˜•์‹์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ 'LOGGER_FORMAT' ํ™˜๊ฒฝ ๋ณ€์ˆ˜์˜ ๊ฐ’ ๋˜๋Š” '%(์‹œ๊ฐ„)-%(๋ ˆ๋ฒจ๋ช…)-%(๋ฉ”์‹œ์ง€)-%(๋ฉ”์‹œ์ง€)'์ž…๋‹ˆ๋‹ค.

None
log_level str

๋กœ๊ฑฐ์˜ ๋กœ๊ทธ ๋ ˆ๋ฒจ์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ๊ฐ’์€ 'LOGGER_LEVEL' ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ๋˜๋Š” 'INFO'์˜ ๊ฐ’์ž…๋‹ˆ๋‹ค.

None
์˜ ์†Œ์Šค ์ฝ”๋“œ hub_sdk/helpers/logger.py
def __init__(self, logger_name=None, log_format=None, log_level=None):
    """
    Initialize a Logger instance.

    Args:
        logger_name (str): Name of the logger. If not provided, defaults to the root logger.
        log_format (str): Format for log messages. Defaults to the value of 'LOGGER_FORMAT'
                         environment variable or '%(asctime)s - %(levelname)s - %(message)s'.
        log_level (str): 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()

๊ตฌ์„ฑ๋œ ๋กœ๊ฑฐ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค:

์œ ํ˜• ์„ค๋ช…
Logger

๊ตฌ์„ฑ๋œ ๋กœ๊ฑฐ ์ธ์Šคํ„ด์Šค์ž…๋‹ˆ๋‹ค.

์˜ ์†Œ์Šค ์ฝ”๋“œ hub_sdk/helpers/logger.py
def get_logger(self) -> logging.Logger:
    """
    Get the configured logger instance.

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