Skip to main content

Django logging in database

Project description

https://travis-ci.org/CiCiUi/django-db-logger.svg?branch=master

Django logging in database. For large projects please use Sentry

Screenshot

https://ciciui.github.io/django-db-logger/static/img/django-db-logger.png

Dependency

  • Django>=1.9

  • Python 2.7+/3.6+

License

WTFPL

Quick start

  1. Install

pip install django-db-logger
  1. Add “django_db_logger” to your INSTALLED_APPS setting like this

INSTALLED_APPS = (
    ...
    'django_db_logger',
)
  1. Add handler and logger to LOGGING setting like this

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'verbose': {
            'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
        },
        'simple': {
            'format': '%(levelname)s %(asctime)s %(message)s'
        },
    },
    'handlers': {
        'db_log': {
            'level': 'DEBUG',
            'class': 'django_db_logger.db_log_handler.DatabaseLogHandler'
        },
    },
    'loggers': {
        'db': {
            'handlers': ['db_log'],
            'level': 'DEBUG'
        },
        'django.request': { # logging 500 errors to database
            'handlers': ['db_log'],
            'level': 'ERROR',
            'propagate': False,
        }
    }
}
  1. Run python manage.py migrate to create django-db-logger models.

  2. Use django-db-logger like this

import logging
db_logger = logging.getLogger('db')

db_logger.info('info message')
db_logger.warning('warning message')

try:
    1/0
except Exception as e:
    db_logger.exception(e)

Options

  1. DJANGO_DB_LOGGER_ADMIN_LIST_PER_PAGE: integer. list per page in admin view. default 10

  2. DJANGO_DB_LOGGER_ENABLE_FORMATTER: boolean. Using formatter options to format message. True or False, default False

Build your own database logger :hammer:

  1. Create a new app and add it to INSTALLED_APPS

  2. Copy files django-db-logger/models.py, django-db-logger/admin.py, django-db-logger/db_log_handler.py to the app folder

  3. Replace DJANGO_DB_LOGGER_ADMIN_LIST_PER_PAGE in admin.py with an integer

  4. Replace DJANGO_DB_LOGGER_ENABLE_FORMATTER in db_log_handler.py with True or False. Remove MSG_STYLE_SIMPLE, it was not used.

  5. Replace logger class django_db_logger.db_log_handler.DatabaseLogHandler in your Settings with the new logger class

  6. Customize the looger to meet your needs. :beer:

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-logger-0.1.13.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

django_db_logger-0.1.13-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file django-db-logger-0.1.13.tar.gz.

File metadata

  • Download URL: django-db-logger-0.1.13.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for django-db-logger-0.1.13.tar.gz
Algorithm Hash digest
SHA256 a299a08638a741eb0b1d192f2a27eae57ed5118673c2aa916467f2e060c24e72
MD5 a4a8bb6cafa0b021e0bb41ecef03293a
BLAKE2b-256 b94d7a599b6c0c5ad63386ffff10b865e5729ba40a1fd49c8b152d71c62f7bb1

See more details on using hashes here.

File details

Details for the file django_db_logger-0.1.13-py3-none-any.whl.

File metadata

File hashes

Hashes for django_db_logger-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 7a1741468c4dc5e7f7cb6f06e1981b16cedff81d3d04d8d926c82b814a247133
MD5 7ff61f9a5c592e2293ce92cf0850cd57
BLAKE2b-256 0944da602c708b8c12e6603f2e1429b670e2988823b0a194ad1b4bccb344a77e

See more details on using hashes here.

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