Coder Social home page Coder Social logo

errorhandler's Introduction

Travis Coveralls Docs PyPI

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.

As an example, first, you set up the error handler:

>>> from errorhandler import ErrorHandler
>>> e = ErrorHandler()

Then you can log and check the handler at any point to see if it has been triggered:

>>> e.fired
False
>>> from logging import getLogger
>>> logger = getLogger()
>>> logger.error('an error')
>>> e.fired
True

You can use the fired attribute to only perform 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

Installation

Do the following in your virtualenv:

pip install errorhandler

Documentation

The latest documentation can also be found at: http://errorhandler.readthedocs.org/en/latest/

Licensing

Copyright (c) 2008-2015 Simplistix Ltd, 2016 Chris Withers. See docs/license.txt for details.

errorhandler's People

Contributors

cjw296 avatar

Stargazers

 avatar Deep Mukherjee avatar @mkarots avatar  avatar Daniel Himmelstein avatar

Watchers

 avatar James Cloos avatar Chrissy Donaldson avatar

errorhandler's Issues

errorhandler disables default logging output to stderr

Great package! It does exactly what I needed. This repo took me a while to find, but it's an honor to be the first user to star it! The use case it solves seems like it should be pretty common, especially with the growing use of continuous integration builds. I answered a StackOverflow question with this package.

I'm adding errorhandler to our project in manubot/manubot#2. One thing that confused me at first was that adding error handler suppressed the default logging to stderr. I'm not sure whether this is intentional or a bug. Anyways, here's the code I used to get the stderr logging back:

error_handler = errorhandler.ErrorHandler()
logger = logging.getLogger()
logger.setLevel(getattr(logging, args.log_level))
stream_handler = logging.StreamHandler(stream=sys.stderr)
logger.addHandler(stream_handler)

Is this the simplest workaround?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.