Python 配置日志
Python 2.6+
def cfgLogging():
from logging.handlers import RotatingFileHandler
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
Rthandler = RotatingFileHandler('/var/log/abc.log', maxBytes=10*1024*1024,backupCount=5)
Rthandler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s %(name)-12s: %(levelname)-8s | %(message)s')
Rthandler.setFormatter(formatter)
console.setFormatter(formatter)
mainlogger = logging.getLogger('')
mainlogger.addHandler(Rthandler)
mainlogger.addHandler(console)
mainlogger.setLevel(logging.INFO)
Python2.7+
#coding:utf-8 import logging.config def cfgLogging():
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'default': {'format': '[%(asctime)-25s] [%(relativeCreated)-15s] %(name)-12s pid:%(process)d %(message)s'},
# default': {
# 'format' : '%(asctime)s %(message)s',
# 'datefmt' : '%Y-%m-%d %H:%M:%S'
# }
},
'handlers': {
'console':{
'level':'DEBUG',
'class':'logging.StreamHandler',
'formatter': 'default'
},
'file': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'default',
'filename' : 'runlog.log',
'maxBytes': 20 * 1024 * 1024, # 10M
'backupCount': 5,
'encoding' : 'utf8',
}
},
'loggers' : {
# 定义了一个logger
'' : {
'level' : 'DEBUG',
'handlers' : ['console', 'file'],
'propagate' : True
}
}
}
logging.config.dictConfig(LOGGING)
Python 配置日志的更多相关文章
- Python 配置日志的几种方式
Python配置日志的几种方式 作为开发者,我们可以通过以下3种方式来配置logging: (1)使用Python代码显式的创建loggers,handlers和formatters并分别调用它们的配 ...
- python配置日志的几种方式
使用的是logging模块,关于logging模块内容,可以看我的另一篇博客:https://www.cnblogs.com/kuxingseng95/p/9464347.html 作为开发者,我们一 ...
- Python根据系统环境配置日志,Python配置日志 Python logger
我们通常在写爬虫的时候,需要配置日志,但是有可能是在windows开发的,但是程序的运行环境可是是在Linux中,这时候我们就需要不停的更换日志的目录了 但是我们可以实现通过判断不同的运行环境,来时间 ...
- Python logging(日志)模块
python日志模块 内容简介 1.日志相关概念 2.logging模块简介 3.logging模块函数使用 4.logging模块日志流处理流程 5.logging模块组件使用 6.logging配 ...
- python之配置日志的三种方式
以下3种方式来配置logging: 1)使用Python代码显式的创建loggers, handlers和formatters并分别调用它们的配置函数: 2)创建一个日志配置文件,然后使用fileCo ...
- Python之配置日志的几种方式(logging模块)
原文:https://blog.csdn.net/WZ18810463869/article/details/81147167 作为开发者,我们可以通过以下3种方式来配置logging: 1)使用Py ...
- 【转】python之配置日志的几种方式
[转]python之配置日志的几种方式 作为开发者,我们可以通过以下3种方式来配置logging: 1)使用Python代码显式的创建loggers, handlers和formatters并分别调用 ...
- python之配置日志的几种方式
作为开发者,我们可以通过以下3种方式来配置logging: 1)使用Python代码显式的创建loggers, handlers和formatters并分别调用它们的配置函数: 2)创建一个日志配置文 ...
- python 日志的配置,python对日志封装成类,日志的调用
# python 日志的配置,python对日志封装成类,日志的调用 import logging # 使用logging模块: class CLog: # --------------------- ...
随机推荐
- mtk开发
mtk套接字所有的声明放在soc_api.h 条件编译命令最常见的形式为: ? 1 2 3 4 5 #ifdef标识符 //程序段1 #else //程序段2 #endif 它的作用是:当标识符已经被 ...
- pysproto bug修复
最近,找隔壁组的同学测试了一下我的pysproto,他们提了很多有益的建议,非常感谢. 在测试中,出现了一次诡异的coredump.当数据变大的时候,就有很大的机率遇上double free.在spr ...
- Express4.x常用API(一):res
最近在学习NodeJS,用到了express,看着官网上的API手册,打算把其中比较常用到的API根据自己理解翻译一下,方便自己学习使用. 该篇打算用来记录下express中res. 由于水平有限,希 ...
- assign、copy 、retain等关键字的含义
assign: 简单赋值,不更改索引计数copy: 建立一个索引计数为1的对象,然后释放旧对象retain:释放旧的对象,将旧对象的值赋予输入对象,再提高输入对象的索引计数为1Copy其实是建立了一个 ...
- Lua C++ Binding之Lunar, Luna
服务端引擎的脚本, 我们项目在老端游项目上发展, 采取的是Lua脚本. 当前服务端的发展趋势是瘦引擎, 胖脚本模式, 基本上引擎负责的功能非常少, 主要是网络, 定帧, 定时器, 引擎通过导出相应的接 ...
- requestAnimationFrame
(function() { var lastTime = 0; var vendors = ['webkit', 'moz']; for(var x = 0; x < vendors.lengt ...
- JavaScript 的循环语句语法摘要
if条件语句语法: if(condition){ statements; } 理解:圆括号里的是条件参数 ,花括号里的为执行的语句. 示例代码:if(1>2){ alert("Th ...
- 【耐克】【空军一号 Nike Air Force 1】【软木塞】
[高帮 全白 36-45] [空军一号 低帮 36-46] [空军一号 36-45] [Nike Air Force 1 Flyknit 空军中帮飞线系列 全黑 36-44] [耐克空军一号 软木塞 ...
- openacs与easycwmp的对接
原创作品,转载请注明出处 copyright:weishusheng 2015.3.18 email:642613208@qq.com 平台: Linux version 2.6.32-279.e ...
- DBA-mysql-init-password-5.7
1.Mysql5.7 Password; 查找临时密码:grep "A temporary password" /var/log/mysqld.log 修改临时密码:alter ...