Package: django-peavy
django-peavyis a tool for improving your Django application logging.FeaturesMiddleware to tag each request with a unique ID.Logging filters to capture request metadata like user, remote IP, and headers.Logging handlers for:Capturing exception information, including a copy of the Django server
error page, in a database.Sending error notifications to admins without revealing sensitive
information like the contents of request.POST.A database router for sending log records to a separate database.A simple user interface for browsing log records in the database.InstallationStart with Django 1.3 or higher; peavy is intended for use with the new logging
configuration first available in that version.To install, simply run:pip install django-peavyConfigurationAddpeavyto yourINSTALLED_APPSsetting.Add the peavy database router:DATABASE_ROUTERS = ['peavy.routers.DjangoDBRouter']Create a dedicated database for logging.If you want to name it something other than ‘peavy’, you’ll need to specify
it insettings.PEAVY_DATABASE_NAME.The separate database makes schema management a little trickier than usual.
It needs to contain South’s migration history table as well as Peavy’s log
records.So first, run syncdb on your default database:$ django-admin.py syncdbAnd of course if you have other apps using South, migrate them:$ django-admin.py migrateThis will actually create peavy tables in your default database. Sorry for
the debris; South isn’t yet obeying database routers.Now on to peavy’s database:$ django-admin.py syncdb --database=peavyThen run Peavy’s South migrations:$ django-admin.py migrate peavy --database=peavy(Of course, if you chose a different name for the database, use that in
these last two commands.)If you omit the app name, you may encounter errors with other apps whose
migrations South tries to run.Add the logging configuration. For example:LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'default': {
            'format': '[%(asctime)s %(name)s %(levelname)s] %(message)s'
        },
        'basic': {
            'format': '[%(asctime)s %(uuid)s %(user_pk)s:%(username)s %(name)s %(levelname)s] %(message)s'
        },
        'meta': {
            'format': '[%(asctime)s %(client_ip)s %(uuid)s %(user_pk)s:%(username)s %(name)s %(levelname)s] %(message)s'
        },
    },
    'filters': {
        'basic': {
            '()': 'peavy.filters.BasicFilter',
        },
        'meta': {
            '()': 'peavy.filters.MetaFilter',
        }
    },
    'handlers': {
        'null': {
            'level':'DEBUG',
            'class':'django.utils.log.NullHandler',
        },
        'console': {
            'level':'DEBUG',
            'class':'logging.StreamHandler',
            'filters': ['basic', 'meta'],
            'formatter': 'basic'
        },
        'mail_admins': {
            'level': 'ERROR',
            'class': 'peavy.handlers.AdminEmailHandler',
            'filters': ['basic', 'meta'],
            'formatter': 'meta'
        },
        'peavy': {
            'level': 'INFO',
            'class': 'peavy.handlers.DjangoDBHandler',
            'filters': ['basic', 'meta'],
            'formatter': 'meta'
        }
    },
    'loggers': {
        'django': {
            'handlers': ['null'],
            'propagate': True,
            'level':'INFO',
        },
        'django.request': {
            'handlers': ['peavy', 'mail_admins'],
            'level': 'ERROR',
            'propagate': False,
        },
        'myapp': {
            'handlers': ['console', 'peavy'],
            'level':'DEBUG',
        }
    }
}Addpeavy.middleware.RequestLoggingMiddlewareto MIDDLEWARE_CLASSES.Adddjango.core.context_processors.requestto TEMPLATE_CONTEXT_PROCESSORS.The last two steps can be skipped if you don’t want the UI.If desired, addpeavy.urlsto your URL configuration to get the UI:urlpatterns += patterns('',
    (r'^peavy/', include('peavy.urls', namespace='peavy')),
)Runmanage.py collectstaticto copy peavy’s media into place.Demo ApplicationPeavy comes with an example application that demonstrates how to log with it,
and lets you check out the UI. To run it:Create a virtualenv for it, then activate the virtualenv.Copy the example application from your copy of django-peavy into the virtualenv:$ rsync -av peavy_demo/ $VIRTUAL_ENV/peavy_demo/Install its requirements with pip:$ pip install -r $VIRTUAL_ENV/peavy_demo/requirements.txtSet up the PostgreSQL databases to match the Django settings (see step 2
under Configuration, above). You can of course use another database, but it
has to support concurrent transactions (so sqlite is out), and you’ll have
to adjust the settings and install the adapter yourself.Adjust your PYTHONPATH to pick up the demo app:$ export PYTHONPATH=$VIRTUAL_ENV:$PYTHONPATHSet the DJANGO_SETTINGS_MODULE environment variable:$ export DJANGO_SETTINGS_MODULE=peavy_demo.settingsRun the devserver:$ django-admin.py runserverBrowse tohttp://localhost:8000/, enter a movie quote, then check the loggingathttp://localhost:8000/peavy/.NotesQ. Why “peavy”?
A. Seehttp://en.wikipedia.org/wiki/Peavey_%28tool%29. It’s a lumberjack tool,
and it’s OK. Oh, come on, it’srequired.Futuresupport for logging to other sinks: message queues, non-relational databases.