This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

Various logging-related utilities for Django projects. For now, it provides a LoggingMiddleware class and an EventLogger class.

Quickstart

Install django-logutils:

pip install django-logutils

LoggingMiddleware

LoggingMiddleware is middleware class for Django, that logs extra request-related information. To use it in your Django projects, add it to your MIDDLEWARE_CLASSES setting:

MIDDLEWARE_CLASSES = (
    ...
    'django_logutils.middleware.LoggingMiddleware',
    ...
)

The extra information consists of:

  • event (default: ‘request’)
  • remote ip address: the remote ip address of the user doing the request.
  • user email: the email address of the requesting user, if available
  • request method: post or get
  • request url path
  • response status code
  • content length of the response body
  • request time

N.B.: event can be overriden by using the LOGUTILS_LOGGING_MIDDLEWARE_EVENT setting in your project.

The log message itself is a string composed of the remote ip address, the user email, the request method, the request url, the status code, the content length of the body and the request time. Additionally, a dictionary with the log items are added as an extra keyword argument when sending a logging statement.

If settings.DEBUG is True or the request time is more than 1 second, two additional parameters are added to the logging dictionary: nr_queries that represents the number of queries executed during the request-response cycle and sql_time that represents the time it took to execute those queries. Slow requests are also raised to a loglevel of WARNING.

N.B.: the time threshold for slow requests can be overriden by using the LOGUTILS_REQUEST_TIME_THRESHOLD setting in your project.

EventLogger

The EventLogger class makes it easy to create dictionary-based logging statements, that can be used by log processors like Logstash. Log events can be used to track metrics and/or to create visualisations.

Here’s an example of how you can use it:

>>> from django_logutils.utils import EventLogger
>>> log_event = EventLogger('my_logger')
>>> log_event('my_event', {'action': 'push_button'})

Development

Install the test requirements:

$ pip install -r requirements/test.txt

Run the tests to check everything is fine:

$ make test

To run the tests and opening the coverage html in your browser:

$ make coverage

To run flake8 and pylint, do:

$ make lint

To generate the documentation, do:

$ make docs

History

0.4.2 (2015-10-30)

  • Support StreamingHttpResponse that doesn’t have content length.

0.4.1 (2015-08-21)

  • Add tests for app settings.

0.4.0 (2015-08-20)

  • Make REQUEST_TIME_THRESHOLD a setting.

0.3.1 (2015-08-04)

  • Update documentation.

0.3.0 (2015-08-04)

  • Add EventLogger class.

0.2.5 (2015-07-31)

  • Reach 100% test coverage.

0.2.4 (2015-07-31)

  • Improve project structure.

0.2.3 (2015-07-30)

  • Add log_event utility function for logging events.

0.2.2 (2015-07-29)

  • Add add_items_to_message utility function.

0.2.1 (2015-07-29)

  • More and better tests.

0.2.0 (2015-07-28)

  • Release replacing previous faulty dev release.

0.1.0 (2015-07-28)

  • First release on PyPI.
Release History

Release History

0.4.2

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.4.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.3.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.5

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.4

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.3

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.2.0

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django_logutils-0.4.2-py2.py3-none-any.whl (9.8 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Oct 30, 2015
django-logutils-0.4.2.tar.gz (8.4 kB) Copy SHA256 Checksum SHA256 Source Oct 30, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting