Although the Python standard library provides a logging system, you should consider having a look at Logbook for your applications. Currently logbook is an alpha version and should be considered a developer preview.
But give it a try, we think it will work out for you and be fun to use :)
Furthermore because it was prototyped in a couple of days, it leverages some features of Python that are not available in older Python releases. Logbook currently requires Python 2.4 or higher including Python 3 (3.1 or higher, 3.0 is not supported).
If properly configured, Logbook’s logging calls will be very cheap and provide a great performance improvement over an equivalent configuration of the standard library’s logging module. While for some parts we are not quite at performance we desire, there will be some further performance improvements in the upcoming versions.
It also supports the ability to inject additional information for all logging calls happening in a specific thread or for the whole application. For example, this makes it possible for a web application to add request-specific information to each log record such as remote address, request URL, HTTP method and more.
The logging system is (besides the stack) stateless and makes unit testing it very simple. If context managers are used, it is impossible to corrupt the stack, so each test can easily hook in custom log handlers.
Logbook is an addon library to Python and working in an area where there are already a couple of contestants. First of all there is the standard library’s logging module, secondly there is also the warnings module which is used internally in Python to warn about invalid uses of APIs and more. We know that there are many situations where you want to use either of them. Be it that they are integrated into a legacy system, part of a library outside of your control or just because they are a better choice.
Because of that, Logbook is two-way compatible with logging and one-way compatible with warnings. If you want, you can let all logging calls redirect to the logbook handlers or the other way round, depending on what your desired setup looks like. That way you can enjoy the best of both worlds.
Logging should be fun. A good log setup makes debugging easier when things go rough. For good results you really have to start using logging before things actually break. Logbook comes with a couple of unusual log handlers to bring the fun back to logging. You can log to your personal twitter feed, you can log to mobile devices, your desktop notification system and more.
This is how easy it is to get started with Logbook:
from logbook import warn
warn('This is a warning')
That will use the default logging channel. But you can create as many as you like:
from logbook import Logger
log = Logger('My Logger')
log.warn('This is a warning')
Here a list of things you can expect in upcoming versions: