Home

Python ErrorNot Notifier

ErrorNot is an errors agregator that let you track your errors without overflooding your inbox.

The Python ErrorNot notifier comes in two flavors:

  • a WSGI application,
  • a logging handler.

Installation

easy_install errornot_notifier

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!

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http:www.fsf.org/licensing/licenses/agpl-3.0.html.

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.