Python的Logging使用教程
来源:互联网 发布:java中的compare 编辑:程序博客网 时间:2024/06/06 03:50
Pyhton的logging功能非常强大,附上平时经常使用的一段代码
这个open_logging的作用有2个:
1.命令窗口输出log;
2.将log写入到文件中;
</pre><pre name="code" class="python"># -*- coding:UTF-8 -*-__author__ = 'gancj'__data__ = '2015-05-30 11:28'__mail__ = 'chaojiang.gcj@alibaba-inc.com/393037282@qq.com'import loggingimport timedef get_now_time(): today_date = str(time.strftime('%Y-%m-%d-%H',time.localtime(time.time()))) return today_datedef open_logging(): logging.basicConfig(level=logging.NOTSET, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='{}applicationrunning.log'.format(get_now_time()), filemode='a') #日志级别CRITICAL > ERROR > WARNING > INFO > DEBUG > NOTSET,数值大小是,50,40,...0,当然也可以自己定义日志级别,自己输入数字。 console = logging.StreamHandler() console.setLevel(logging.INFO) formatter = logging.Formatter('%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s') console.setFormatter(formatter) logging.getLogger('').addHandler(console)
0 0
- Python的Logging使用教程
- python logging模块使用教程
- python的logging使用
- Python的logging使用
- python logging的使用
- 使用Python的logging.config
- 使用Python的logging.config
- 使用python的logging模块
- 使用python的logging模块
- 使用python的logging模块
- 【python系列】logging的使用
- 使用python的logging模块
- 使用python的logging模块
- 使用python的logging模块
- 使用python的logging模块
- 使用python的logging模块
- 【python】logging模块的使用
- 使用python的logging模块
- jQuery的deferred对象详解
- 谈谈3D打印成本之中的奥秘
- 杭电3501Calculation 2 欧拉函数
- SpringMVC+Mysql实例详解
- mahout安装测试
- Python的Logging使用教程
- 黑马程序员_Collection集合之Set
- POJ1905-----Expanding Rods
- selenium 找元素的方法
- 技术类
- 字典树
- 从3D打印成本来看3D打印的预测
- maven工程目录中各个文件的作用
- 【面试题之算法部分】二叉树的遍历