ErrorHandler 1.0.0 Released!

Chris Withers chris at
Fri Jun 19 11:21:11 CEST 2009

I'm pleased to finally get around to announcing the release of ErrorHandler.

This is a handler for the python standard logging framework that can
be used to tell whether messages have been logged at or above a
certain level.

This can be useful when wanting to ensure that no errors have been
logged before committing data back to a database.

Here's an example:

First, you set up the error handler:

 >>> from logging import getLogger
 >>> from errorhandler import ErrorHandler
 >>> logger = getLogger()
 >>> e = ErrorHandler()

The handler started off being un-fired:

 >>> e.fired

Then you do whatever else you need to do, which may involve logging:

 >>>'some information')
 >>> e.fired

However, if any logging occurs at an error level or above:

 >>> logger.error('an error')

Then the error handler becomes fired:

 >>> e.fired

You use this as a condition to only do certain actions when no errors
have been logged:

 >>> if e.fired:
...   print "Not updating files as errors have occurred"
Not updating files as errors have occurred

If your code does work in batches, you may wish to reset the error
handler at the start of each batch:

 >>> e.reset()
 >>> e.fired

For more information, please see:



Simplistix - Content Management, Zope & Python Consulting

More information about the Python-announce-list mailing list