Python示例-Logging
[loggers]
keys=root,demo [handlers]
keys=consoleHandler,timedRotatingFileHandler [formatters]
keys=simpleFmt [logger_root]
level=DEBUG
handlers=consoleHandler [logger_demo]
level=DEBUG
handlers=timedRotatingFileHandler
qualname=demo
propagate=0 [handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=simpleFmt
args=(sys.stdout,) [handler_timedRotatingFileHandler]
class=handlers.TimedRotatingFileHandler
level=DEBUG
formatter=simpleFmt
args=("demo.log", "d", 1, 0) [formatter_simpleFmt]
format=%(asctime)s - %(name)s - [%(filename)s:%(lineno)s]- %(levelname)s - %(message)s
datefmt=
使用示例:
import logging
import logging.config logging.config.fileconfig("logging.ini")
logger = logging.getLogger("demo") if __name__ == "__main__":
logger.debug('This is debug message')
logger.info('This is info message')
logger.error('This is error message')
demo.log日志文件示例:
2018-10-16 21:40:27,104 - demo - [log_record.py:15]- DEBUG - This is debug message
2018-10-16 21:40:27,105 - demo - [log_record.py:16]- INFO - This is info message
2018-10-16 21:40:27,105 - demo - [log_record.py:17]- ERROR - This is error message
Python示例-Logging的更多相关文章
- python模块 ---logging模块
摘要by crazyhacking: 与log4cxx一样,分为三个部分,logger, handler,formatter. 详细内容参考:1官网http://docs.python.org/2/h ...
- 【python】logging日志模块写入中文编码错误解决办法
一.问题: 使用python的logging模块记录日志,有时会遇到中文编码问题错误. 二.解决办法: 在logging.FileHandler(path) 中添加指定编码方式 encoding='u ...
- Python中logging模块的基本用法
在 PyCon 2018 上,Mario Corchero 介绍了在开发过程中如何更方便轻松地记录日志的流程. 整个演讲的内容包括: 为什么日志记录非常重要 日志记录的流程是怎样的 怎样来进行日志记录 ...
- 转 使用Python的logging.config.fileConfig配置日志
Python的logging.config.fileConfig方式配置日志,通过解析conf配置文件实现.文件 logglogging.conf 配置如下: [loggers]keys=root,f ...
- python之 logging 模块(上篇)
一.日志关概念 日志是一种可以追踪某些软件运行时所发生事件的方法.软件开发人员可以向他们的代码中调用日志记录相关的方法来表明发生了某些事情.一个事件可以用一个可包含可选变量数据的消息来描述.此外,事件 ...
- Python之logging模块
一.引言 之前在写一些小程序的时候想把日志内容打到文件中,所以就自己写了一个logger.py的程序,如下: #!/usr/bin/python # -*- coding=utf-8 -*- impo ...
- python的logging模块
python提供了一个日志处理的模块,那就是logging 导入logging模块使用以下命令: import logging logging模块的用法: 1.简单的将日志打印到屏幕上 import ...
- python 多进程 logging:ConcurrentLogHandler
python 多进程 logging:ConcurrentLogHandler python的logging模块RotatingFileHandler仅仅是线程安全的,如果多进程多线程使用,推荐 Co ...
- python的logging模块之读取yaml配置文件。
python的logging模块是用来记录应用程序的日志的.关于logging模块的介绍,我这里不赘述,请参见其他资料.这里主要讲讲如何来读取yaml配置文件进行定制化的日志输出. python要读取 ...
随机推荐
- linux 生成密钥和公钥,实现免密登录
1. 在相应的用户根目录下生成密钥公钥,输入如下命令: ssh-keygen -t rsa 2. 直接三次回车:会生成两个文件:id_rsa / id_rsa.pub,分别为密钥和公钥 3. 打开公 ...
- VxWorks引导启动过程
https://blog.csdn.net/phunxm/article/details/6979089
- 洛谷 P1282 多米诺骨牌 ( 线性DP )
题意 : 题目链接 分析 : 一开始这个想法也有想到,但是貌似要开很大数组,就感觉应该不行 遂放弃想其他方法,万万没想到注意到可以滚动优化(其实不优化也可以过) 定义 dp[i][j] 表示 到第 ...
- 点云数据中的三维信息提取pcl
https://www.hanspub.org/journal/PaperInformation.aspx?paperID=24702 https://wenku.baidu.com/view/160 ...
- android 文件保存到应用和sd卡中
<span style="font-size:18px;">1.权限添加 <uses-permission android:name="android. ...
- 关于option标签的selected属性
当item的dict_id和custSource一样,那么当前的item的name就被选中并显示在页面 如果直接写selected="selected",就等于直接回显这个集合中最 ...
- Vue/Element-ui 安装搭建开发环境(一)
Element 是饿了么全段开发团队推出的一套基于 vue.js2.0 的 PC Web 端开发框架. Element 中文文档:https://element.eleme.cn/#/zh-CN 1. ...
- linux下面用Mingw编译libx264
linux下面用Mingw编译libx264 首先要先安装好mingw 我用的是Ubuntu 编译ffmpeg的时候 ,官方上面有一个自动化脚本能够把mingw安装好 这里就不说了 新版本的libx2 ...
- 【转】UNITY中相机空间,投影空间的正向问题
原文链接1:https://www.cnblogs.com/wantnon/p/4570188.html 原文链接2:https://www.cnblogs.com/hefee/p/3820610.h ...
- KVM 常用命令
显示虚拟机 virsh list --all 停止虚拟机 virsh destroy <name> 启动虚拟机 virsh start <name> 删除虚拟机 virsh u ...