[Python] logging.logger
<1>.
mylogger = logging.getLogger("abc")
logging.debug()/logging.info()/logging.warning()/logging.error()等使用的是全局的root logger实例, mylogger是一个新实例,它默认继承root logger的设置。
The root of the hierarchy of loggers is called the root logger. That’s the logger used by the functions debug(), info(), warning(), error() and critical(), which just call the same-named method of the root logger. The functions and the methods have the same signatures. The root logger’s name is printed as 'root' in the logged output.
<2>.
A good convention to use when naming loggers is to use a module-level logger, in each module which uses logging, named as follows:
logger = logging.getLogger(__name__)
This means that logger names track the package/module hierarchy, and it’s intuitively obvious where events are logged just from the logger name.
<3>.
getLogger() returns a reference to a logger instance with the specified name if it is provided, or root if not. The names are period-separated hierarchical structures. Multiple calls to getLogger() with the same name will return a reference to the same logger object.
def loggerDemo():
logging.basicConfig(filemode="w", level=logging.DEBUG) #filemode not working for logger()?
loggerOut = logging.getLogger("output")
#loggerOut.setLevel(logging.DEBUG)
#创建一个handler,用于写入日志文件
fh = logging.FileHandler(os.path.join(os.getcwd(),"{0}_debug.log".format(__name__ if __name__ != "__main__" else "basicPython")))
formatter = logging.Formatter("%(asctime)s - %(message)s")
fh.setFormatter(formatter)
loggerOut.addHandler(fh)
loggerOut.debug("hello in Logger(Output)")
loggerErr = logging.getLogger("error")
#loggerErr.setLevel(logging.ERROR)
#创建一个handler,用于写入日志文件
fh = logging.FileHandler(os.path.join(os.getcwd(),"{0}_error.log".format(__name__ if __name__ != "__main__" else "basicPython")))
formatter = logging.Formatter("%(asctime)s - %(message)s")
fh.setFormatter(formatter)
loggerErr.addHandler(fh)
loggerErr.debug("hello in Logger(Error)")
loggerDemo()
**References:**
[Python之Logger](http://blog.csdn.net/kzjay/article/details/5655039)
[Logging HOWTO](https://docs.python.org/2.7/howto/logging.html#logging-basic-tutorial)
[Python中的logger和handler到底是个什么鬼](http://www.cnblogs.com/anpengapple/p/5048123.html)
[Python] logging.logger的更多相关文章
- python logging
参考: https://docs.python.org/2/howto/logging.html#logging-basic-tutorial https://docs.python.org/2/li ...
- python logging模块详解[转]
一.简单将日志打印到屏幕: import logging logging.debug('debug message') logging.info('info message') logging.war ...
- python logging模块
1.logging模块提供了四个组件logger:日志类,有两个功能1)配置日志的等级,处理器handler,过滤器filterlogger.setLevel(logging.INFO)logger. ...
- python logging模块可能会令人困惑的地方
python logging模块主要是python提供的通用日志系统,使用的方法其实挺简单的,这块就不多介绍.下面主要会讲到在使用python logging模块的时候,涉及到多个python文件的调 ...
- python logging 配置
python logging 配置 在python中,logging由logger,handler,filter,formater四个部分组成,logger是提供我们记录日志的方法:handler是让 ...
- Python LOGGING使用方法
Python LOGGING使用方法 1. 简介 使用场景 场景 适合使用的方法 在终端输出程序或脚本的使用方法 print 报告一个事件的发生(例如状态的修改) logging.info()或log ...
- python logging 日志轮转文件不删除问题
前言 最近在维护项目的python项目代码,项目使用了 python 的日志模块 logging, 设定了保存的日志数目, 不过没有生效,还要通过contab定时清理数据. 分析 项目使用了 logg ...
- python logging模块使用
近来再弄一个小项目,已经到收尾阶段了.希望加入写log机制来增加程序出错后的判断分析.尝试使用了python logging模块. #-*- coding:utf-8 -*- import loggi ...
- python Logging的使用
日志是用来记录程序在运行过程中发生的状况,在程序开发过程中添加日志模块能够帮助我们了解程序运行过程中发生了哪些事件,这些事件也有轻重之分. 根据事件的轻重可分为以下几个级别: DEBUG: 详细信息, ...
随机推荐
- Softmax回归推导过程
http://www.cnblogs.com/Deep-Learning/p/7073744.html http://www.cnblogs.com/lutingting/p/4768882.html ...
- php -- 四种基础排序:冒泡、选择、插入、快速
冒泡排序 思路分析:法如其名,就是像冒泡一样,每次从数组当中 冒一个最大的数出来. 第一轮:从第一个到最后一个冒泡比较,运行结果:最后一个最大 第二轮:从第一个到倒数第二个冒泡比较, 运行结果:最后一 ...
- C语言若干知识点归记
一.C语言指针学习架构 1.基本数据类型---指针 2.字符串---指针 3.数组---指针 4.函数---指针 5.结构体---指针 6.共用体---指针 7.枚举---指针 8.位域---指针 9 ...
- CPictureEx类
CPictueEx类不仅可以显示GIF(包括GIF动画),还可以显示JPEG.BMP.WMF.ICO.CUR等. 参考:https://www.codeproject.com/Articles/142 ...
- Dynamics CRM 2015 Update 1 系列(3): API的那些事 - Old APIs VS New APIs
今天我们来看看API的变化.新系统中,去掉了一些经常使用的数据处理API,比如:SetStateRequest, SetBusinessUnitRequest, SetParentBusinessUn ...
- IOS 开发之 -- 过滤掉字符串里面所有的非法字符 字典和json之间的互转
比如一个字符串: NSString * hmutStr = @"(010)*(123)E6(234)**150-1111-^^-1234#" 很多时候,数据之间的传输,我们仅仅只想 ...
- onTouch事件分发
事件机制 我们知道view中有onTouch,onClick, 1.并且onTouch优先于onClick执行, 2.onTouch有返回值,为true时onClick并不再执行了 因为一切VIew都 ...
- 使用JSP表达式和JSP脚本打印九九乘法表
首先使用JSP声明声明一个函数用于得到九九乘法表的内容 <%! String printMultiTable() { String s = ""; for (int i = ...
- spring @Transactional注解参数详解(转载)
事物注解方式: @Transactional 当标于类前时, 标示类中所有方法都进行事物处理 , 例子: 1 @Transactional public class TestServiceBean i ...
- js数组和字符串去重复几种方法
js数组去重复几种方法 第一种:也是最笨的吧. Array.prototype.unique1 = function () { var r = new Array(); label:for(var i ...