标签类目:Logging

Python的标准logging模块

分类:Python

Python Standard Logging

Python的标准logging模块

Python 2.3 introduced the logging module to the Python standard library. logging provides a standard interface for outputting information from a running application. The classic example of a logging mechanism is writing data to a text file, which is a plain old log file. While the log file is likely the most common form of logging, the logging module provides the ability to send information to file-like objects, TCP and UDP sockets, email servers, the Unix syslog, the NT event log, memory buffers, and HTTP servers in addition to “real” files.

从Python2.3起,Python的标准库加入了logging模块.logging模块给运行中的应用提供了一个标准的信息输出接口.典型的logging机制实现是把要输出的数据简单地写到一个txt文件中去.写log文件的方式是一种常见的打log的方式,而logging模块提供的更多,它可以把输出信息输出到所有类文件的对象中去,甚至TCP和UDP的sockets,email服务器,Unix的syslog系统,NT系列的事件log系统,内存的buffer和HTTP服务器,当然还有”真正的”文件中去. 继续阅读 »

python中日志Logging模块的简单使用

分类:Python

  1. def initlog():
  2.     import logging
  3.     logger = logging.getLogger()
  4.     hdlr = logging.FileHandler(logfile)
  5.     formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
  6.     hdlr.setFormatter(formatter)
  7.     logger.addHandler(hdlr)
  8.     logger.setLevel(logging.NOTSET)
  9.     return logger

继续阅读 »


返回顶部