EADST

Print Info in the Terminal and Save Logs in a File

Print Info in the Terminal and Save Logs in a File

import logging

log_name = "test"
logging.basicConfig(filename="{}.log".format(log_name), format='%(asctime)s %(message)s', filemode='w') 
sh = logging.StreamHandler()
logger=logging.getLogger() 
logger.setLevel(logging.DEBUG) 
logger.addHandler(sh)

logger.debug("Level lowest message") 
logger.info("Regular message") 
logger.warning("Warning message") 
logger.error("Error message") 
logger.critical("Fatal message") 

Reference

Python Logging

相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
站点统计

本站现有博文266篇,共被浏览440708

本站已经建立2019天!

热门文章
文章归档
回到顶部