Coder Social home page Coder Social logo

django-db-logging's Introduction

Django DB Logging

image

image

image

Database logging handler with Django integration

This package contains two handlers fully compatible with python logging sub-system. They allow to use standard logging functionalities and display log using Django Admin interface.

This package is not intented to be used in production for high traffic web sites, it, instead, has been developed to help a rapid troubleshooting in following scenarions:

  • User Acceptant Test environment
  • Small/Medium traffic application
  • Cloud environments where developer do not have access to logs

It contains two handlers:

  • `DBHandler`: synchronous logging to database
  • `AsyncDBHandler`: asynchronous logging to database. It helps to reduce the 'per request' user response time

Installation

pip install django-db-logging

Update your settings:

INSTALLED_APPS = [
    ...
    'admin_extra_urls',
    'django_db_logging',
    ]

LOGGING = {
    ...
    'handlers': {
        'db': {
            'level': 'DEBUG',
            'class': 'django_db_logging.handlers.AsyncDBHandler',
        },

    },
    'loggers': {
        '': {
            'handlers': ['db', 'console'],
            'level': 'ERROR'
        },
        'django_db_logging': {
            'handlers': ['console'],  # do not use 'db' here
            'propagate': False,  # do not propagate
            'level': 'ERROR'
        },
    }
}

DBLOG = {
    "MAX_LOG_ENTRIES" : 10000,  # max entries to keep
    "ENABLE_TEST_BUTTON": True, # Display 'Test' button in admin
    "ALLOW_TRUNCATE": True,     # Display 'Empty Log' button
    "USE_CRASHLOG":  False,     # enable django-crashlog integration
}

It now possible use standard logging functionalities and see check logs in the Admin site.

Note It's better do not use this as unique handler, database connection can fails and you could loose your log. Always add extra handler.

django-crashlog integration

DBLogger can be integrated with [django-crashlog](https://github.com/saxix/django-crashlog) everytime an exception in logged (using logger.exception) an entry in django-crashlog is automatically created without the needs to use process_exception

Logs cleanup

If you use [celery]() or any other task runner you can schedule a daily cleanup running django_db_logging.models.Record.objects.cleanup to delete all but config.MAX_LOG_ENTRIES most recent lines

Use custom models

It is possible to customize handlers to use dedicated Model:

from django_db_logging.models import AbstractRecord


class CustomLogger(AbstractRecord):
    class Meta:
        app_label = 'demo'

and in your settings:

LOGGING = {
    ...
    'handlers': {
        'db': {
            'level': 'DEBUG',
            'class': 'django_db_logging.handlers.AsyncDBHandler',
            'model': 'demo.CustomLogger',
        },

    },
    ...
Stable master-build master-cov
Development dev-build dev-cov
Project home page: https://github.c om/saxix/django -db-logging
Issue tracker: https://github.c om/saxix/django -db-logging/issues?sort
Download: http://pypi.pyth on.org/pypi/dja ngo-db-logging/
Documentation: https://django-d b-logging.readt hedocs.org/en/latest/

django-db-logging's People

Contributors

domdinicola avatar saxix avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.