日志
def comnLogger(logfile,name): handler = logging.FileHandler(logfile, mode="a+", encoding="utf-8") myformat = "%(asctime)s [task_id:%(name)s] %(filename)s [line:%(lineno)d]:%(levelname)s %(message)s" formatter = logging.Formatter(myformat) handler.setFormatter(formatter) mylogger = logging.getLogger(name) mylogger.addHandler(handler) mylogger.setLevel(logging.DEBUG) return mylogger # loggkafka = comnLogger(logfile_path1,'kafka.conn') log_syscnc = comnLogger(logfile_path2,'sysncdata') loggkafka.info(msg) #logfile_path1 log_syscnc.error(msg) #logfile_path2 #注意TimedRotatingFileHandler按时间将日志文件切分 handler = TimedRotatingFileHandler(logfile, when = 'D', interval = 1, backupCount=0)