0x02 Python logging模块利用配置加载logger
logging模块利用配置加载logger
logging.config模块提供了从配置加载创建logger等相关对象,并放入manager对象中进行缓存待用。所以记录下一般几种方式配置的范本模式,方便项目中copy直接修改使用。
dict config references 官档关于logging配置字典说明
方式一模板:logging.config.dictConfig(config_dict)
config_dict 字典模板
cfg = {
'version': 1,
'formatters': {
'detailed': {
'class': 'logging.Formatter',
'format': '%(asctime)s %(name)-15s %(levelname)-8s %(processName)-10s %(message)s'
}
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'level': 'INFO',
},
'file': {
'class': 'logging.FileHandler',
'filename': 'mplog.log',
'mode': 'w',
'formatter': 'detailed',
},
'foofile': {
'class': 'logging.FileHandler',
'filename': 'mplog-foo.log',
'mode': 'w',
'formatter': 'detailed',
},
'errors': {
'class': 'logging.FileHandler',
'filename': 'mplog-errors.log',
'mode': 'w',
'level': 'ERROR',
'formatter': 'detailed',
},
},
'loggers': {
'foo': {
'handlers': ['foofile']
}
},
'root': {
'level': 'DEBUG',
'handlers': ['console', 'file', 'errors']
},
}
模板二:
LOGGER_CONFIG_DICT = {
'version': 1,
'formatters': {
'detailed_fmt': {
'class': 'logging.Formatter',
'format': '%(asctime)s %(created)s %(levelname)-6s %(name)-15s %(processName)s:%(threadName)s %(message)s'
# human-readable timestamp levelname logger_name processname threadname message
},
'simple_fmt': {
'class': 'logging.Formatter',
'format': '%(asctime)s %(levelname)-8s %(name)-15s %(message)s'
# human-readable levelname logger_name message
},
'portal_fmt': {
'class': 'logging.Formatter',
# 'datefmt': '%Y-%m-%d %H:%M:%S,uuu', # 实际默认格式就是这个
'format': '%(asctime)s %(levelname)-8s %(name)-15s %(processName)-10s %(message)s'
},
'system_fmt': {
'class': 'logging.Formatter',
'format': '%(asctime)s %(name)-15s %(levelname)-8s %(processName)-10s %(message)s'
},
},
'handlers': {
# 'console_hd': {
# 'class': 'logging.StreamHandler',
# 'level': 'INFO'
# },
'time_rotate_file_hd': {
'class': 'logging.handlers.TimedRotatingFileHandler',
'filename': './logs/selfservices1.log',
'when': 'M',
'interval': 5,
'backupCount': 100,
'formatter': 'simple_fmt'
},
'file_size_rotate_hd': {
'class': 'logging.handlers.RotatingFileHandler',
'filename': './logs/portal.log',
'mode': 'a',
'maxBytes': 1024 * 1024 * 5,
'backupCount': 50,
'formatter': 'portal_fmt'
},
'errors_hd': {
'class': 'logging.FileHandler',
'filename': './logs/errors.log',
'formatter': 'detailed_fmt',
'level': 'ERROR' # 只会错误40及以上的日志
},
'system_hd': {
'class': 'logging.FileHandler',
'filename': './logs/system.log',
'formatter': 'simple_fmt'
}
},
'loggers': {
'selfservices': {
'level': 'INFO',
'handlers': ['file_size_rotate_hd', 'errors_hd']
# 'handlers': ['time_rotate_file_hd', 'file_size_rotate_hd', 'errors_hd']
}
},
'root': {
'level': 'DEBUG',
'handlers': ['system_hd', 'errors_hd']
},
}
0x02 Python logging模块利用配置加载logger的更多相关文章
- 0x01 Python logging模块
目录 Python logging 模块 前言 logging模块提供的特性 logging模块的设计过程 logger的继承 logger在逻辑上的继承结构 logging.basicConfig( ...
- 基于python的opcode优化和模块按需加载机制研究(学习与个人思路)(原创)
基于python的opcode优化和模块按需加载机制研究(学习与思考) 姓名:XXX 学校信息:XXX 主用编程语言:python3.5 个人技术博客:http://www.cnblogs.com/M ...
- 利用ChromeOptions()加载用户配置
一. 如何绕过页面登录 我们在登录网站的时候,通常需要输入用户名.密码和验证码,那么有没有办法绕过登录环节呢? 有两种方法可以解决这个问题,一种是利用chrome浏览器的用户配置,一种是利用cooki ...
- Python logging模块无法正常输出日志
废话少说,先上代码 File:logger.conf [formatters] keys=default [formatter_default] format=%(asctime)s - %(name ...
- (转)python logging模块
python logging模块 原文:http://www.cnblogs.com/dahu-daqing/p/7040764.html 1 logging模块简介 logging模块是Python ...
- 读懂掌握 Python logging 模块源码 (附带一些 example)
搜了一下自己的 Blog 一直缺乏一篇 Python logging 模块的深度使用的文章.其实这个模块非常常用,也有非常多的滥用.所以看看源码来详细记录一篇属于 logging 模块的文章. 整个 ...
- Python logging 模块学习
logging example Level When it's used Numeric value DEBUG Detailed information, typically of interest ...
- Python logging 模块简介
Table of Contents 1. Logging 模块 1.1. 简介 1.2. 简单输出日志 1.3. 输入日志到文件 1.4. 几个基本概念 1.4.1. loggers 1.4.2. h ...
- Log4j2源码分析系列:(一)配置加载
前言 在实际开发项目中,日志永远是一个绕不开的话题.本系列文章试图以slf4j和log4j2日志体系为例,从源码角度分析日志工作原理. 学习日志框架,首先要熟悉各类日志框架,这里推荐两篇文章,就不再赘 ...
随机推荐
- 论文阅读笔记六十五:Enhanced Deep Residual Networks for Single Image Super-Resolution(CVPR2017)
论文原址:https://arxiv.org/abs/1707.02921 代码: https://github.com/LimBee/NTIRE2017 摘要 以DNN进行超分辨的研究比较流行,其中 ...
- centos7中运行ifconfig提示“-bash: ifconfig: command not found”解决方案
linux系统查看ip地址常用命令是[ifconfig], CentOS 7.0最小安装是没有ifconfig命令怎么办? 1.用[ip addr]查看; 2.就是安装ifconfig命令 1.输入[ ...
- html表格及列表
表格的属性: border:边框 cellpadding:内边距 单元格边框跟内容之间的间距 cellspacing:外边距 单元格跟单元格之间的距离 align:表格的对其样式 width:宽度 ...
- 【oracle】ceil函数 返回值 (大于参数的最小整数)
SELECT CEIL(15.8) FROM DUAL;==========16 SELECT CEIL(-15.8) FROM DUAL;==========-15
- 【java】获取昨天/今天/明天日期
昨天: SimpleDateFormat sdf=new SimpleDateFormat("yyyMMdd"); Calendar calendar = new Gregoria ...
- Linux性能优化实战学习笔记:第二十一讲
一 内存性能指标 1.系统内存使用情况 共享内存:是通过tmpfs实现的,所以它的大小也就是tmpfs使用的大小了tmpfs其实也是一种特殊的缓存 可用内存:是新进程可以使用的最大内存它包括剩余内存和 ...
- [原创]A/B测试系统调研思维导图
[原创]A/B测试系统调研思维导图
- Swagger简单介绍
一句话介绍 Swagger Swagger是一个接口文档生成工具,同时提供接口测试调用的辅助功能. 关于 Swagger Swagger能成为最受欢迎的REST APIs文档生成工具之一,有以下几个原 ...
- oracle数据库表约束、视图、索引—该记录为本人以前微博的文章
一.Oracle 数据库常用操作续关于创建表时创建约束1.创建表的时候增加约束----约束是定义表中的数据应该遵循的规则或者满足的条件----约束是建立在列上的,让某一列或者某几列数据之间有约束--- ...
- vertica 设置最大会话数
默认会话数最大值55,如果超过了,就会报如下错误: com.vertica.support.exceptions.NonTransientConnectionException: [Vertica][ ...