logging.handlers — 日志处理程序

源代码: Lib/logging/handlers.py


包中提供了下列有用处理程序。注意,其中 3 个处理程序 ( StreamHandler , FileHandler and NullHandler ) 实际定义在 logging 模块本身,但已文档化在此除其它处理程序外。

StreamHandler

The StreamHandler 类,位于核心 logging 包,将日志记录输出发送给流,譬如 sys.stdout , sys.stderr 或任何像文件对象 (或更准确地说,任何对象支持 write() and flush() 方法)。

class logging. StreamHandler ( stream = None )

返回新的实例化 StreamHandler 类。若 stream 有指定,实例将使用它为日志记录输出;否则, sys.stderr 会被使用。

emit ( record )

If a formatter is specified, it is used to format the record. The record is then written to the stream followed by terminator . If exception information is present, it is formatted using traceback.print_exception() and appended to the stream.

flush ( )

刷新流通过调用其 flush() 方法。注意, close() method is inherited from Handler and so does no output, so an explicit flush() call may be needed at times.

setStream ( stream )

Sets the instance’s stream to the specified value, if it is different. The old stream is flushed before the new stream is set.

参数 :

stream – The stream that the handler should use.

返回 :

the old stream, if the stream was changed, or None if it wasn’t.

3.7 版添加。