How to use multiple handlers with Logbook?

I use a logbook to register a message in a Python application, but

import logbook

from logbook import Logger, StreamHandler, NullHandler

log = Logger('LogbookExample')

import sys
StreamHandler(sys.stdout).push_application()

NullHandler().push_application()

def main():
    log.info('Hello, World!')    

if __name__ == "__main__":
    main()

doesn't work as I expected ... nothing appears. For example, if NullHandlerreplacesStreamHandler

So wondering how to connect multiple handlers to the application?

+4
source share
1 answer

The problem is the choice NullHandler. It acts like a black hole, absorbing all the magazines and not spreading them onto the stack.

Laying is not NullHandlereasy:

StreamHandler(sys.stdout).push_application()
StreamHandler(sys.stderr, bubble=True).push_application()

The keyword bubblemeans that the handler should continue to spread across the stack after processing the record.

+2
source

Source: https://habr.com/ru/post/1650403/


All Articles