<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的更多相关文章

  1. python logging

    参考: https://docs.python.org/2/howto/logging.html#logging-basic-tutorial https://docs.python.org/2/li ...

  2. python logging模块详解[转]

    一.简单将日志打印到屏幕: import logging logging.debug('debug message') logging.info('info message') logging.war ...

  3. python logging模块

    1.logging模块提供了四个组件logger:日志类,有两个功能1)配置日志的等级,处理器handler,过滤器filterlogger.setLevel(logging.INFO)logger. ...

  4. python logging模块可能会令人困惑的地方

    python logging模块主要是python提供的通用日志系统,使用的方法其实挺简单的,这块就不多介绍.下面主要会讲到在使用python logging模块的时候,涉及到多个python文件的调 ...

  5. python logging 配置

    python logging 配置 在python中,logging由logger,handler,filter,formater四个部分组成,logger是提供我们记录日志的方法:handler是让 ...

  6. Python LOGGING使用方法

    Python LOGGING使用方法 1. 简介 使用场景 场景 适合使用的方法 在终端输出程序或脚本的使用方法 print 报告一个事件的发生(例如状态的修改) logging.info()或log ...

  7. python logging 日志轮转文件不删除问题

    前言 最近在维护项目的python项目代码,项目使用了 python 的日志模块 logging, 设定了保存的日志数目, 不过没有生效,还要通过contab定时清理数据. 分析 项目使用了 logg ...

  8. python logging模块使用

    近来再弄一个小项目,已经到收尾阶段了.希望加入写log机制来增加程序出错后的判断分析.尝试使用了python logging模块. #-*- coding:utf-8 -*- import loggi ...

  9. python Logging的使用

    日志是用来记录程序在运行过程中发生的状况,在程序开发过程中添加日志模块能够帮助我们了解程序运行过程中发生了哪些事件,这些事件也有轻重之分. 根据事件的轻重可分为以下几个级别: DEBUG: 详细信息, ...

随机推荐

  1. 关于Unity的C#基础学习(四)

    一.数组 存放同种类型的一组数据,同类+多个 1.定义 int [] int_set; int_set=new int[10];  //在堆上分配出10个int,int_set是数组的引用变量,指向1 ...

  2. 009杰信-创建购销合同Excel报表系列-2-建立购销合同(增删改查)

    前面一篇文章已经分析好了数据库的表,这篇文章针对购销合同表做一个增删改查. 和之前的表的增删该查类似. 项目结构如下:

  3. 【BZOJ】1030: [JSOI2007]文本生成器(递推+ac自动机)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1030 其实做了1009也不会感到很难了,无非将kmp变成了ac自动机. 设f[i,j]表示前i个串当 ...

  4. Merging an upstream repository into your fork

    1. Check out the branch you wish to merge to. Usually, you will merge into master. $ git checkout ma ...

  5. sdut 2154:Shopping(第一届山东省省赛原题,水题)

    Shopping Time Limit: 1000MS Memory limit: 65536K 题目描述 Saya and Kudo go shopping together.You can ass ...

  6. 【转】Native Thread for Win32 A- Create Thread(通俗易懂,非常好)

    http://www.bogotobogo.com/cplusplus/multithreading_win32A.php Microsoft Windows operating system's s ...

  7. ios开发--图文混排(富文本)

    最近准备接一个编辑类的app,所以就查了下相关的功能,并自己试验了下: /** iOS 6之前:CoreText,纯C语言,极其蛋疼 iOS 6开始:NSAttributedString,简单易用 i ...

  8. ios 开发之 -- UILabel的text竖行显示

    让UILabel的内容竖行显示,我经常用一下两种方式: 第一种:使用换行符 \n label.text = @"请\n竖\n直\n方\n向\n排\n列"; label.number ...

  9. 中文转换成Unicode编码 和 Unicode编码转换为中文

    前几天,遇到一个问题,就是在浏览器地址栏传递中文时,出现乱码,考虑了一下,解决方式有很多,我还是采用了转换编码的方式,将中文转换为Unicode编码,然后再解码成中文,以下是实现的过程,非常简单! p ...

  10. Excel 一个工作表进行按行数拆分

    1. 如下Excel表,总共有120多行数据,如何将以50行数据为一个工作表进行拆分 Sub ZheFenSheet() Dim r, c, i, WJhangshu, WJshu, bt As Lo ...