logging日志管理-将日志写入文件

# -*- 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')

 

posted @ 2015-10-20 10:01  Xiao|Deng  阅读(1859)  评论(1编辑  收藏  举报