Skip to content

jzelez/django-db-logger

 
 

Repository files navigation

django-db-logger

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.6
  • Python 2.6+/3.3+

License

MIT

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'
        }
    }
}
  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)

About

Django logging in database

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.6%
  • Shell 0.4%