errornot_notifier iconerrornot_notifier 0.1.0

Python ErrorNot Notifier
errornot_notifier comes in two flavors:

 * a WSGI application,
 * a logging handler.

The configuration

However you decide to use Python ErrorNot notifier, you should set some variables first:

from errornot import notifier

notifier.API_KEY = "900b7e06850c9864f908469c"
notifier.HOST = "localhost:3000"
notifier.API_VERSION = "0.1.0"


The WSGI ErrorNot notifier

You can use the ErrorNot as a WSGI application. You just have to insert it somewhere in your applications stack (as low as possible, if you want to catch all your exceptions). The WSGI notifier will send some info about the request and the environment to ErrorNot. This is recommended way of using ErrorNot notifier in a WSGI web app.

Exemple of a very simple "Hello World" application:

def hello_world(environ, start_response):
 """Very simple WSGI app saying hello.
 """
 start_response('200 OK', [('Content-Type', 'text/html')])
 return ['''< title >Hello %(subject)s< /title >
 < p >Hello World!< /p >''']

def not_found(environ, start_response):
 """Called if no URL matches."""
 start_response('404 NOT FOUND', [('Content-Type', 'text/plain')])
 return ['Not Found']

def routing(environ, start_response):
 path = environ.get('PATH_INFO', '').lstrip('/')
 if path == "hello":
 return hello_world(environ, start_response)
 if path == "error":
 raise AssertionError("error msg")
 return not_found(environ, start_response)

from wsgiref.simple_server import make_server
from errornot import wsgi_notifier

errornot_notifier = wsgi_notifier.WSGINotifier(routing)
srv = make_server('localhost', 8080, errornot_notifier)
srv.serve_forever()


The above application will raise an error if you visit http://localhost:8080/error, and post an error msg to the ErrorNot server you have configured first.

The logging handler

The ErrorNot notifier also has a logger handler, because it might be usefull to use it in a non WSGI application, or to manually trigger errors posting. If you are new to logging facilities in Python, please read http:docs.python.org/library/logging.html.

To use it that way, just bing the handler to one of your loggers, and start logging exceptions. ErrorNot being intended to log errors, the notifier will look in the stack for exceptions and will grab informations about the last raised. As so, it is recommended to use inside except blocks only.

import logging

logging.basicConfig()
logger = logging.getLogger('test')
logger.setLevel(logging.ERROR)
logger.addHandler(notifier.ErrorNotHandler())

# This will post an error:
try:
 raise AssertionError("Evil error")
except Exception, e:
 logger.exception(e)


Have fun!

last updated on:
March 13th, 2010, 0:09 GMT
price:
FREE!
developed by:
Pierre Ruyssen
license type:
AGPL (Affero General Public License) 
category:
ROOT \ Internet \ HTTP (WWW)

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Add your review!

SUBMIT