import logging.handlers
import logging
import sys
# 导入设置
from settings import LOG_FILE_NAME, MAX_BYTES, BACKUP_COUNTS

# 日志相关配置
logger = logging.getLogger()
logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
# ch.setLevel(logging.DEBUG) 
fh = logging.handlers.RotatingFileHandler(
    str(LOG_FILE_NAME),
    mode="a",
    encoding="utf-8",
    maxBytes=int(MAX_BYTES),
    backupCount=int(BACKUP_COUNTS),
)
formatter = logging.Formatter(
    "%(asctime)s - %(module)s - %(funcName)s - line:%(lineno)d - %(levelname)s - %(message)s"
)
ch.setFormatter(formatter)
fh.setFormatter(formatter)
logger.addHandler(ch)  # 将日志输出至屏幕
logger.addHandler(fh)  # 将日志输出至文件
logger = logging.getLogger(__name__)
