🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

django-db-logger

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

django-db-logger

Django logging in database

0.1.13
PyPI
Maintainers
1

================ django-db-logger

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

Django logging in database. For large projects please use Sentry <https://github.com/getsentry/sentry>_

Screenshot

.. image:: https://ciciui.github.io/django-db-logger/static/img/django-db-logger.png :target: https://travis-ci.org/CiCiUi/django-db-logger

Dependency

  • Django>=1.9
  • Python 2.7+/3.6+

License

WTFPL

Quick start

  • Install

.. code-block:: bash

pip install django-db-logger

2. Add "django_db_logger" to your INSTALLED_APPS setting like this

.. code-block:: python

INSTALLED_APPS = (
    ...
    'django_db_logger',
)

3. Add handler and logger to LOGGING setting like this

.. code-block:: python

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,
        }
    }
}

4. Run python manage.py migrate to create django-db-logger models. 5. Use django-db-logger like this

.. code-block:: python

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

  • DJANGO_DB_LOGGER_ADMIN_LIST_PER_PAGE: integer. list per page in admin view. default 10
  • DJANGO_DB_LOGGER_ENABLE_FORMATTER: boolean. Using formatter options to format message. True or False, default False

Build your own database logger :hammer:

  • Create a new app and add it to INSTALLED_APPS
  • Copy files django-db-logger/models.py, django-db-logger/admin.py, django-db-logger/db_log_handler.py to the app folder
  • Replace DJANGO_DB_LOGGER_ADMIN_LIST_PER_PAGE in admin.py with an integer
  • Replace DJANGO_DB_LOGGER_ENABLE_FORMATTER in db_log_handler.py with True or False. Remove MSG_STYLE_SIMPLE, it was not used.
  • Replace logger class django_db_logger.db_log_handler.DatabaseLogHandler in your Settings with the new logger class
  • Customize the looger to meet your needs. :beer:

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts