shell当中记录log,满眼花花的重定向符合,看着很不爽有没有!我喜欢python,就是喜欢这种买个手电筒,备用电池都准备好了的感觉。logging模块很简单,导入模块,定义日志格式。代码中就可以通过logging.info(),logging.warning(),logging.debug()记录日志了。而且立刻感觉整个人好了很多……
import logging
logging.basicConfig(level=logging.DEBUG,
format=‘%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s‘,
datefmt=‘%a, %d %b %Y %H:%M:%S‘,
filename=‘mylog.log‘,
filemode=‘a‘)
logging.info("这是logging模块记录的info")
logging.debug("这是logging模块的debug信息")
logging.warning("这是logging模块的warning信息")本文出自 “烛影摇红” 博客,请务必保留此出处http://gccmx.blog.51cto.com/479381/1612082
原文地址:http://gccmx.blog.51cto.com/479381/1612082