scls scls - 1 year ago 90
Python Question

How to have several handlers using Logbook?

I'm using logbook to log message in a Python app but

import logbook

from logbook import Logger, StreamHandler, NullHandler

log = Logger('LogbookExample')

import sys


def main():'Hello, World!')

if __name__ == "__main__":

doesn't work as I was expecting...
nothing appears. Like if
was replacing

So I wonder how to have several handlers connected to app ?

Answer Source

The problem here is choosing NullHandler. It acts as a "black hole", swallowing all logs and not propagating them up the stack.

Stacking non-NullHandlers is easy:

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

The bubble keyword means the handler should continue propagation up the stack after handling the record.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download