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 配置日志的更多相关文章

  1. Python 配置日志的几种方式

    Python配置日志的几种方式 作为开发者,我们可以通过以下3种方式来配置logging: (1)使用Python代码显式的创建loggers,handlers和formatters并分别调用它们的配 ...

  2. python配置日志的几种方式

    使用的是logging模块,关于logging模块内容,可以看我的另一篇博客:https://www.cnblogs.com/kuxingseng95/p/9464347.html 作为开发者,我们一 ...

  3. Python根据系统环境配置日志,Python配置日志 Python logger

    我们通常在写爬虫的时候,需要配置日志,但是有可能是在windows开发的,但是程序的运行环境可是是在Linux中,这时候我们就需要不停的更换日志的目录了 但是我们可以实现通过判断不同的运行环境,来时间 ...

  4. Python logging(日志)模块

    python日志模块 内容简介 1.日志相关概念 2.logging模块简介 3.logging模块函数使用 4.logging模块日志流处理流程 5.logging模块组件使用 6.logging配 ...

  5. python之配置日志的三种方式

    以下3种方式来配置logging: 1)使用Python代码显式的创建loggers, handlers和formatters并分别调用它们的配置函数: 2)创建一个日志配置文件,然后使用fileCo ...

  6. Python之配置日志的几种方式(logging模块)

    原文:https://blog.csdn.net/WZ18810463869/article/details/81147167 作为开发者,我们可以通过以下3种方式来配置logging: 1)使用Py ...

  7. 【转】python之配置日志的几种方式

    [转]python之配置日志的几种方式 作为开发者,我们可以通过以下3种方式来配置logging: 1)使用Python代码显式的创建loggers, handlers和formatters并分别调用 ...

  8. python之配置日志的几种方式

    作为开发者,我们可以通过以下3种方式来配置logging: 1)使用Python代码显式的创建loggers, handlers和formatters并分别调用它们的配置函数: 2)创建一个日志配置文 ...

  9. python 日志的配置,python对日志封装成类,日志的调用

    # python 日志的配置,python对日志封装成类,日志的调用 import logging # 使用logging模块: class CLog: # --------------------- ...

随机推荐

  1. SQL函数创建错误

    [Err] 1418 - This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration a ...

  2. Array(数组)--map方法

    关于Array.prototype.map() MDN 给的定义是: 在作用数组元素的每一项上调用一个方法(callback),返回一个新数组: 使用格式:arr.map(callback[,this ...

  3. 《Android深度探索HAL与驱动开发》第一章阅读心得

    首先了解到Android系统架构是由四层构成:其中第一层是Linux内核,他的作用是负责Linux的驱动程序以及内存.进程.电源等管理操作:第二层是C/C++代码库,也就是Linux下.so的文件:第 ...

  4. Scrolliview

    package com.example.scrollview; import android.os.Bundle;import android.app.Activity;import android. ...

  5. 通过js的console优雅的将php调试信息输出

    function consoleLog($val){ $debug = debug_backtrace(); unset($debug[0]['args']); echo '<script> ...

  6. JS 获取地址栏三级域名

    <script type="text/javascript"> function Char(str) { var uchars = {}; str.replace(/\ ...

  7. 【jq】c#零基础学习之路(4)抽象类和密封

    一.抽象类 1.抽象类不能被实例化 2.抽象类方法必需要实现 3.如何类中函数为抽象函数,其类也需要定义成抽象类 4.关键字 abstract ,函数重写 override. 二.密封类 1.密封类不 ...

  8. ASP.NET Razor——ASP.NET Razor - C#代码语法

    Razor 同时支持 C# (C sharp) 和 VB (Visual Basic). 主要的 Razor C# 语法规则 Razor 代码块包含在 @{ ... } 中 内联表达式(变量和函数)以 ...

  9. 另类分析SIGSEGV信号

    关于SIGSEGV信号的含义就不解释了.网络上有很多解释. 今天记录一下,自己遇到的一个问题,想了好几天都没想出来的.今天终于想到原因了. 过程描述: 有个类 CBase,里面放了一个成员变量 DAT ...

  10. 好的bootstrap文章

    http://www.cnblogs.com/gamehiboy/p/5176618.html http://www.cnblogs.com/landeanfen/p/5821192.html htt ...