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

Custom DB Log Handler for Django Projects.

Documentation

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

Quickstart

Install Django DB Log:

pip install django-db-log-plugin

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    '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:

TO DO

  • release on PyPI

  • create tags

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.

Source Distribution

django_db_log_plugin-0.1.2.tar.gz (9.7 kB view hashes)

Uploaded Source

Built Distribution

django_db_log_plugin-0.1.2-py2.py3-none-any.whl (11.1 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page