需要再加入按照日期生成日志
#coding:utf-8
import logging
import logging.handlers
class Logger:logFile = ''def __init__(self, logFile):self.logFile = logFileself.logger = logging.getLogger('mylogger')self.logger.setLevel(logging.INFO)rf_handler = logging.handlers.TimedRotatingFileHandler(self.logFile, when='midnight', interval=1, backupCount=7)rf_handler.setFormatter(logging.Formatter("%(asctime)s - %(levelname)s - %(message)s"))self.logger.addHandler(rf_handler)def log(self, model, msg):self.logger.info(model + "-->" + msg)logMan = Logger('log.log')
logMan.log("XMLFileWatcher", "new xml file finded:" + '/*/1.xml')