理解StreamHandler||FileHandler in logging.handlers

  • logging.handlers

  • StreamHandler

    The StreamHandler class, located in the core logging package, sends logging output to streams such as sys.stdout, sys.stderr or any file-like object(or, more precisely, any object which supports write() and flush() methods.)

    class logging.StreamHandler(stream=None)

    Returns a new instance of the StreamHandler class. If stream is specified, the instance will use it for logging output; otherwise, sys.stderr will be used.

    • emit(record)
    • flush()
    • setStream(stream)
  • FileHandler

    The FileHandler class, located in the core logging package, sends logging output to a disk file. It inherits the output functionality from StreamHandler.

    class logging.FileHandler(filename, mode="a", encoding=None, delay=False)

    Returns a new instance of the FileHandler class.

    The specified file is opened and used as the stream for logging.

    If mode is not specified, ‘a’ is used.

    If encoding is not None, it is used to open the file with that encoding.

    If delay is true , then file opening is deferred until the first call to emit().

    By default, the file grows indefinitely.

    • close()
    • emit(record)
  • NullHandler

    The NullHandler class, located in the core logging package, does not do any formatting or output. It is essentially a “no-op” handler for use by library developers.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章