<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. 如果想要跨平台,在file类下有separtor(),返回锁出平台的文件分隔符

    对于命令:File f2=new file(“d:\\abc\\789\\1.txt”) 这个命令不具备跨平台性,因为不同的OS的文件系统很不相同. 如果想要跨平台,在file类下有separtor( ...

  2. NANDflash和NORflash的区别(设计师在使用闪存时需要慎重选择)

    NANDflash和NORflash的区别(设计师在使用闪存时需要慎重选择)     NOR和NAND是现在市场上两种主要的非易失闪存技术.Intel于1988年首先开发出NOR flash技术,彻底 ...

  3. 小结:双连通分量 & 强连通分量 & 割点 & 割边

    概要: 各种dfs时间戳..全是tarjan(或加上他的小伙伴)无限膜拜tarjan orzzzzzzzzz 技巧及注意: 强连通分量是有向图,双连通分量是无向图. 强连通分量找环时的决策和双连通的决 ...

  4. PowerShell中的配置文件

    http://www.cnblogs.com/ceachy/archive/2013/03/01/PowerShell_Profile.html

  5. Using XSLT and Open XML to Create a Word 2007 Document

    Summary: Learn how to transform XML data into a Word 2007 document by starting with an existing docu ...

  6. JQuery------图片幻灯片插件

    下载地址: http://www.jq22.com/jquery-info36

  7. cocos2d-x 3.0 使用.plist图片集方法

    这个贴.仅仅是为了和我一样的新手,更快的索引. 我使用的是SpritePacker 软件来制作 .plist SpriteFrameCache *frameCache = SpriteFrameCac ...

  8. 应用开发之Linq和EF

    本章简言 上一章笔者对于WinForm开发过程用到的几个知识点做了讲解.笔者们可以以此为开端进行学习.而本章我们来讲一个跟ORM思想有关的知识点.在讲之前让我们想一下关于JAVA的hibernate知 ...

  9. Egret微端 创建项目(一)

    开发环境: window7 egret engine:5.0.14 egret wing:4.1.0 微端:v0.0.14 官方教程:http://developer.egret.com/cn/git ...

  10. Android 代码规范 code style

    /* * 文件名(可选),如 CodingRuler.java * * 版本信息(可选),如:@version 1.0.0 * * 版权申明(开源代码一般都需要添加),如:Copyright (C) ...