Python logging 模块简单实用
2018-04-11 01:48
513 查看
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=’debuglog.log’,
filemode=’a+’)#定义格式
console = logging.StreamHandler()
console.setLevel(logging.INFO)#定义记录水平
formatter = logging.Formatter(‘%(name)-12s: %(levelname)-8s %(message)s’)
console.setFormatter(formatter)
logging.getLogger(”).addHandler(console)
logging.debug(‘this is debug’) #不被记录 -这个是由console.setLevel(logging.INFO)决定
logging.info(‘this is info’) #不被记录 -这个是由console.setLevel(logging.INFO)决定
logging.warning(‘this is warn’) #被记录-这个是由console.setLevel(logging.INFO)决定
logging.error(‘this is error’) #被记录-这个是由console.setLevel(logging.INFO)决定
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=’debuglog.log’,
filemode=’a+’)#定义格式
console = logging.StreamHandler()
console.setLevel(logging.INFO)#定义记录水平
formatter = logging.Formatter(‘%(name)-12s: %(levelname)-8s %(message)s’)
console.setFormatter(formatter)
logging.getLogger(”).addHandler(console)
logging.debug(‘this is debug’) #不被记录 -这个是由console.setLevel(logging.INFO)决定
logging.info(‘this is info’) #不被记录 -这个是由console.setLevel(logging.INFO)决定
logging.warning(‘this is warn’) #被记录-这个是由console.setLevel(logging.INFO)决定
logging.error(‘this is error’) #被记录-这个是由console.setLevel(logging.INFO)决定
相关文章推荐
- python logging模块的简单使用
- Python的logging模块的简单应用
- [Python学习]Logging模块的简单使用
- Python Logging模块的简单使用
- [Python学习] Logging模块的简单使用
- python —— 使用logging模块简单实现日志系统
- python中的sockeserver模块简单实用
- logging in python: logging模块的简单使用
- python中的sockeserver模块简单实用
- Python Logging模块的简单使用
- Python中的fileinput模块的简单实用示例
- Python Logging模块的简单使用
- Python中的fileinput模块的简单实用示例
- python中logging日志模块使用(简单配置、完成配置、多进程)
- 简单的logging模块调用(python)
- Logging模块的简单使用 Python
- python之logging模块
- python:使用socket模块,进行服务器与客户端简单交互
- python-nmap模块的使用及制作一个简单的端口扫描器
- python 之logging 模块