Python3.x:logging模块对运行过程记录详解编程语言

Python3.x:logging模块对运行过程记录

示例:

import logging 
 
# 设置 
logger = logging.getLogger() 
#set loghandler 
#默认路径 
file = logging.FileHandler("yzzq_jys.log") 
#文件在py所在的目录下 
file = logging.FileHandler(sys.path[0]+"/yzzq_log"+time.strftime("%Y%m%d")+".log") 
logger.addHandler(file) 
#set formater 
formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s") 
file.setFormatter(formatter)  
#set log level 
logger.setLevel(logging.NOTSET) 
 
#调用 
if __name__ == '__main__': 
    logger.info("传递参数错误,参数依次(参数之间用空格隔开)") 

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/16778.html

(0)
上一篇 2021年7月19日 19:37
下一篇 2021年7月19日 19:37

相关推荐

发表回复

登录后才能评论