博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python Logging模块的简单使用
阅读量:4681 次
发布时间:2019-06-09

本文共 774 字,大约阅读时间需要 2 分钟。

#-*- coding: utf-8 -*- #!/usr/bin/pythonimport logging# create loggerlogger = logging.getLogger('simple_example')logger.setLevel(logging.DEBUG)# create console handler and set level to debugch = logging.StreamHandler()ch.setLevel(logging.DEBUG)# create formatterformatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')# add formatter to chch.setFormatter(formatter)# add ch to loggerlogger.addHandler(ch)LOG_FILENAME = './logging_example.out'logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG,)# 'application' codelogger.debug('debug message')logger.info('info message')logger.warn('warn message')logger.error('error message')logger.critical('critical message')

2种日志显示是一致的,可以单独设置

 

参考文档:

转载于:https://www.cnblogs.com/alamZ/p/6894931.html

你可能感兴趣的文章
java
查看>>
[laravel] Laravel - composer install
查看>>
20190218日记
查看>>
python day2 模块初识、pyc定义
查看>>
一道算法作业题(续)
查看>>
Machine Learning From Scratch-从头开始机器学习
查看>>
基础数据结构
查看>>
python url库学习
查看>>
找“水王”
查看>>
Advanced Views and URLconfs(The Definitive Guild to Django)
查看>>
CodeForces 132C 一道简单 dp
查看>>
018-伸展树
查看>>
FPM打包工具
查看>>
JDK版本不兼容问题之:一台机器安装多个版本的JDK
查看>>
2016年 前端学习网站
查看>>
20145302张薇《Java程序设计》第八周学习总结
查看>>
JavaScript之数组的常用操作函数
查看>>
Python之时间表示
查看>>
jmeter参考网址
查看>>
【算法导论】简单哈希表的除法实现
查看>>