import logging

from src.system_var.environment import LOG_LEVEL

# boto3関連モジュールのログレベルを事前に個別指定し、モジュール内のDEBUGログの表示を抑止する
for name in ["boto3", "botocore", "s3transfer", "urllib3"]:
    logging.getLogger(name).setLevel(logging.WARNING)


def get_logger(log_name: str) -> logging.Logger:
    """一意のログ出力モジュールを取得します。

    Args:
        log_name (str): ロガー名

    Returns:
        _type_: _description_
    """
    logger = logging.getLogger(log_name)
    level = logging.getLevelName(LOG_LEVEL)
    if not isinstance(level, int):
        level = logging.INFO
    logger.setLevel(level)

    if not logger.hasHandlers():
        handler = logging.StreamHandler()
        logger.addHandler(handler)

        formatter = logging.Formatter(
            '%(name)s\t[%(levelname)s]\t%(asctime)s\t%(message)s',
            '%Y-%m-%d %H:%M:%S'
        )

        for handler in logger.handlers:
            handler.setFormatter(formatter)

    return logger
