# -*- coding: cp936 -*-# test.py#http://blog.chinaunix.net/uid-27571599-id-3492860.html#logging日志管理#将日志写入文件import logging#创建日志log文件,注意是log后缀log_filename='loggingTest.log'#设置日志格式log_format='%(filename)s [%(asctime)s] [%(levelname)s] %(message)s'#设置时间格式datetime='%Y-%m-%d %H:%M:%S'#设置日志输出格式和级别#filemode:以什么模式操作文件logging.basicConfig(filename=log_filename,filemode='w',format=log_format,datetime=datetime,level=logging.DEBUG)logging.debug('this message debug')logging.info('xiaodeng')logging.warning('python')