Python 输出 log 到文件的方法

import logging
from
logging.handlers import RotatingFileHandler module_name = "test_module" Rthandler = RotatingFileHandler("/var/lib/test_log/%s.log" % (module_name), maxBytes=10 * 1024 * 1024, backupCount=5) Rthandler.setLevel(logging.INFO) formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s") Rthandler.setFormatter(formatter) logger = logging.getLogger(module_name) logging.basicConfig(level=logging.NOTSET) logger.addHandler(Rthandler)
原文地址:https://www.cnblogs.com/liujx2019/p/11176833.html