import logging

from src.system_var.environments import LOG_LEVEL

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


class Logger():
    __logger: logging.Logger

    def __init__(self):
        self.__logger = logging.getLogger()

        level = logging.getLevelName(LOG_LEVEL)
        if not isinstance(level, int):
            level = logging.INFO
        self.__logger.setLevel(level)

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

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

            for handler in self.__logger.handlers:
                handler.setFormatter(formatter)

    def get_logger(self) -> logging.Logger:
        return self.__logger


logger_instance = Logger().get_logger()
