1 / 40
文档名称:

Python的logging模块.doc

格式:doc   页数:40页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

Python的logging模块.doc

上传人:wc69885 2015/6/5 文件大小:0 KB

下载得到文件列表

Python的logging模块.doc

相关文档

文档介绍

文档介绍:Python的logging模块
Python, by Stephen.
初次使用logging模块觉得有点诡异,涉及到Logger、Handler、Level等概念,看代码最实际了:
view source
print?
01
import logging
02
import sys 
03
  
04
logger = ("endlesscode")
05
formatter = ('%(name)-12s %(asctime)s %(levelname)-8s %(message)s', '%a, %d %b %Y %H:%M:%S',)
06
file_handler = ("")
07
(formatter)
08
stream_handler = ()
09
(file_handler)
10
(stream_handler)
11
#()
12
  
13
("fuckgfw")
14
  
15
(stream_handler)
16
("fuckgov")
文档上已经说明得很清楚了,有几个比较特别的地方:
如果设置了setLevel的日志等级,则调用比设定低的日志记录函数则不会有任何的输出,比如:
view source
print?
1
()
2
#没有生效,默认的info<error
3
("fuckgfw")
一个logger如果添加了多个handler(),记录的时候会同时在多个hanlder上输出日志。
,其初始化的参数如下:
onfig的成员函数,主要是用来配置一些基本的信息:
view source
print?
1
(
2
    level=,
3
    format='%(name)-12s %(asctime)s %(levelname)-8s %(message)s',
4
    datefmt='%a, %d %b %Y %H:%M:%S',
5
    filename=log_file,
6
    filemode='a')
文档上的说明:
view source
print?
1
Does basic configuration for the logging system by creating a StreamHandler with a default Formatter and adding it to the root logger. The functions debug(), info(), warning(), error() and critical() will call onfig() automatically if no handlers are defined for the root logger.
参数如下:
Back Top
python多logging写日志
Posted by admin on 2010 年 10 月 11 日 Leave ment (0) Go ments
      今天想记录日志,一开始就直接用open,write写,发现效率不高,就采用了python的自带模块logging,给大家看个测试代码:
[Copy]View Code PYTHON
1
2
3
4
5
6
7
LOG_FILENAME = '/home/es123/python/test/'
(filename=LOG_FILENAME,level=,)
 
LOG_FILE = '/home/es123/python/test/'
(filename=LOG_FIL