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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM