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. 快速上手RaphaelJS-Instant RaphaelJS Starter翻译(一)

       (目前发现一些文章被盗用的情况,我们将在每篇文章前面添加原文地址,本文源地址:http://www.cnblogs.com/idealer3d/p/Instant_RaphaelJS_Start ...

  2. 快速删除.svn文件夹

    Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\DeleteSVN] @= ...

  3. CLR via C# 3rd - 05 - Primitive, Reference, and Value Types

    1. Primitive Types        Any data types the compiler directly supports are called primitive types. ...

  4. NT6 HDD Installer(硬盘装系统工具)装系统

    32位系统上使用虚拟光驱装不了64位的,使用NT6就可以.

  5. sql中对于case when...then...else...end的写法和理解

    查询配件主数据表(tbl_part_base_info)的所有数据和配件是否有物料(物料表(tbl_material)中有配件主数据表的part_no,就表示有物料,反之,则表示没有物料),用sql中 ...

  6. 新建STM32工程

    1) 2)保存 3)选择公司和芯片的型号,STM32F103C8T6,64kB Flash, 20kB SRAM. 4)手动添加启动代码 5)新建如下文件夹 6)回到工程,选中target,右键Add ...

  7. uploadfy api中文文档

    Uploadify是一款基于JQuery的优秀的文件/图片上传的插件,有基于Flash和HTML5两种版本. Uploadify/uploadifive主要特点有:1. 多文件上传2. 个性化设置3. ...

  8. Django 创建APP简单步骤

    yum install epel-releaseyum install python34yum install python-pippip install django django-admin st ...

  9. 【引】objective-c,6:Autorelease Pool

    参考博客: http://blog.leichunfeng.com/blog/2015/05/31/objective-c-autorelease-pool-implementation-princi ...

  10. 求第K大数

    1.排序找第K个数 2.快速排序分块  时间复杂度  2呢