Saturday 26 December 2015

Python: Logging: Handlers

Handlers are responsible for delivering log messages to external world like console, file, sockets etc., You can attaché more than one handler to logger object.

Following methods are used to add and remove handler from a logger.
Method
Description
Logger.addHandler(hdlr)
Add handler to this logger
Logger.removeHandler(hdlr)
Remove handler from this logger

Filters are used to filter out the log messages. You can attach filters to Loggers, handlers.

Following methods are used to add and remove filter from handler.
Method
Description
Handler.addFilter(filt)
Add filter to this handler
Handler.removeFilter(filt)
Remove filter from this handler

Just like setting logging level, formatters to a logger, you can set logging level and formatters to handlers.

Handler.setLevel(lvl)
Set the level to handler. Logging messages which are less severe than lvl will be ignored. When a handler is created, its level is set to NOTSET, so by default it process all log messages.

Handler.setFormatter(form)
Sets the formatter for this handler.


Previous                                                 Next                                                 Home

No comments:

Post a Comment