Skip to main content

Custom DB Log Handler for Django Projects.

Project description

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:

History

0.1.0 (2018-08-29)

  • First release on PyPI.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django_db_log_plugin-0.1.3-py2.py3-none-any.whl (11.4 kB) Copy SHA256 hash SHA256 Wheel py2.py3
django_db_log_plugin-0.1.3.tar.gz (10.1 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page