Django DB Log

https://badge.fury.io/py/django-db-log-plugin.svg https://travis-ci.org/eduarde/django-db-log.svg?branch=master https://codecov.io/gh/eduarde/django-db-log/branch/master/graph/badge.svg https://img.shields.io/pypi/wheel/django-db-log-plugin.svg

Custom DB Log Handler for Django Projects.

Documentation

The full documentation is at https://django-db-log.readthedocs.io.

Features

  • Capture logs and save them in database.
  • Examine logs in the administration page of the website.
  • Job scheduler to delete old logs from the database.

Quickstart

Install Django DB Log:

pip install django-db-log-plugin

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_apscheduler',
    'django_db_log',
    ...
)

Add Django DB Log’s URL patterns:

from django_db_log import urls as django_db_log_urls


urlpatterns = [
    ...
    url(r'^', include(django_db_log_urls)),
    ...
]

Add the LOGGING configuration in the settings.py file.

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
           'format': '[%(asctime)s] %(levelname)s %(module)s.%(funcName)s %(lineno)d: %(message)s'
        },
        'simple': {
            'format': ' %(levelname)s  %(message)s',
        },
    },
    'handlers': {
        'log_db': {
            'level': 'ERROR',
            'class': 'django_db_log.handlers.DBHandler',
            'model': 'django_db_log.models.ErrorLog',
            'expiry': 86400,
            'formatter': 'simple',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['log_db'],
            'level': 'ERROR',
            'propagate': False,
        },
    },
}

Add the following constants in your settings file. These will be used to determine the lookup days to delete old logs from db.

INTERVAL_SCHEDULER_JOB_SECONDS = 43200
GENERAL_LOGS_DELETE_DAYS = 2
INFO_LOGS_DELETE_DAYS = 2
DEBUG_LOGS_DELETE_DAYS = 2
ERROR_LOGS_DELETE_DAYS = 10

Run migrations

python manage.py migrate

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package: