传统的调试方式是print + openFile,然后这种方式比较繁琐(每次print后要刷新文件缓存),而使用logging模块就会方便很多:
# coding=utf-8
__metaclass__ = type
__author__ = 'dbloop'
import logging
# 配置日志
logging.basicConfig(level = logging.INFO,filename = r'C:\Python27\loggingDir\test001\test001.log')
# 生成日志
logging.info('Start program.')
logging.info('Try to division 1 by 0.')
print 1/0
logging.info('The division succeed!')
logging.info('End program.')
来源:oschina
链接:https://my.oschina.net/u/2690292/blog/661837