from config import Config
import logging

#日志类
class Logger:
    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(Config.LOG_LEVEL)
        self.logger.propagate = False
        formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')

        if not self.logger.handlers:  # 检查是否已经有处理器
            # 输出到控制台
            console_handler = logging.StreamHandler()
            console_handler.setFormatter(formatter)
            self.logger.addHandler(console_handler)
            
            # 输出到文件
            file_handler = logging.FileHandler('app.log')
            file_handler.setFormatter(formatter)
            self.logger.addHandler(file_handler)

logger = None

def get_logger():
    global logger
    if logger is None:
        logger = Logger()
    return logger.logger