Jaktivity is a django app to log activity on a django powered website.
- Django 1.3+
- Put
jaktivity
on your python path - Add
jaktivity
toINSTALLED_APPS
in your settings - syncdb (or run migrations if you are using south)
- Add
jaktivity.middleware.ActivityLogMiddleware
toMIDDLEWARE_CLASSES
in your settings
- Add
jaktivity
to your urls patterns += ('', (r'^activity/', include('jaktivity.urls', namespace='jaktivity')),) Sample templates are available in the sample_templates directory.
For HTTP requests that are 'unsafe' (not having HTTP method GET
or HEAD
):
- date
- remote IP Address
- django auth username (if logged in with django.contrib.auth)
- request method
- request host
- request path
- python path of the view resolved to
- args passed to the view
- response status code (if not 500)
- exception type (if 500)
A view can set a human readable message onto its log entry: def view(request): if request.method == 'POST': request.log.message = 'Edited a widget'
If you want to add messages to views from third party apps, you can simply add a log_message attribute to the view. from django.contrib.auth.views import login login.log_message = 'Logged In'
You can also specify a callable object instead of a string; Jaktivity will call it with the same arguments as the view and assign the result of the callable to the message.
Log entries may have multiple notes attached to them. You can add a note to a log anytime: def view(request): for item in request.POST.getlist('values'): request.log.note("Adding item %s" % item)
By default Jaktivity will not log requests with an HTTP method of GET
or
HEAD
. You can adjust what methods jactivity considers 'safe' (meaning they
will not be logged) by setting ACTIVITY_SAFE_METHODS
in your settings. For
instance, if you do not want to log requests with a DELETE
method, set the
following:
JAKTIVITY_SAFE_METHODS = ('GET', 'HEAD', 'DELETE')
You may override the SAFE_METHODS by marking individual views as always_log
or never_log
:
def view(request):
return HttpResponse()
view.always_log = True
By default, Jaktivity does not save any of the HTTP Headers. You may specify
which headers you would like to save with the ACTIVITY_SAVE_HEADERS
setting.
Example: to save User-Agent strings, add the following to your settings: JAKTIVITY_SAVE_HEADERS = ('HTTP_USER_AGENT',)
Jaktivity records all HTTP parameters, unless they are named any of the following:
- csrfmiddlewaretoken
- password
You may override this list with the JAKTIVITY_IGNORE_PARAMS
setting.
Noah Silas ([email protected])