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)

 

posted on 2019-07-12 16:26  liujx2019  阅读(1785)  评论(0编辑  收藏  举报

导航