import configparser
import logging
from logging.handlers import RotatingFileHandler

config = configparser.ConfigParser()
config.read("config", encoding="utf-8")

def get_logger(config):
    logger = logging.getLogger()
    rotating_log_handler = RotatingFileHandler(filename=config["loggers"]["logfile"], maxBytes=1024*1024*int(config["loggers"]["logMaxSize"]), backupCount=config["loggers"]["logBackupCount"])
    rotating_log_handler.setLevel(logging.DEBUG)
    formatter = logging.Formatter("%(asctime)s-%(filename)s-[line:%(lineno)d]-%(levelname)s: %(message)s")
    rotating_log_handler.setFormatter(formatter)
    logger.addHandler(rotating_log_handler)
    logger.setLevel(logging.DEBUG)
    return logger

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
猜你喜欢
  • 2022-12-23
  • 2021-06-02
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2021-04-10
  • 2022-01-31
相关资源
相似解决方案