django-logdb

Enables you to log entries to a database and aggregate them periodically
Download

django-logdb Ranking & Summary

Advertisement

  • Rating:
  • License:
  • BSD License
  • Price:
  • FREE
  • Publisher Name:
  • Joeri Bekker
  • Publisher web site:
  • http://maykinmedia.nl

django-logdb Tags


django-logdb Description

Enables you to log entries to a database and aggregate them periodically django-logdb has a custom logging handler that writes log entries in a database. It therefore integrates nicely with your existing logging configuration and you can decide what log entries are written to the database.The Django admin site is extended with a graphical view of recent log entries to provide more insight in what is going on. The log messages are grouped by log level or "type of log entry".To minimize database access, aggregation is done via a Django command that you can call periodically (as a cronjob).Installation:The easiest way to install the package is via setuptools:easy_install django-logdbOnce installed, update your Django settings.py and add djangologdb to your INSTALLED_APPS:INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', ... 'djangologdb',)In your Django urls.py, include the djangologdb.urls before the admin:urlpatterns = patterns('', ... (r'^admin/djangologdb/', include('djangologdb.urls')), ... (r'^admin/', include(admin.site.urls)),)Optionally, if you want to log exceptions, add the middleware:MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', ... 'djangologdb.middleware.LoggingMiddleware',)Run python manage.py syncdb to create the database tables.Now, for the actual logging part, you should use the database logging handler. There are two ways to do this: Using only Python code, or, by using a configuration file. Both methods are explained below.To add this handler via Python to, for example, your root logger, you can add the following to your Django settings.py:import loggingfrom djangologdb.handler import DjangoDatabaseHandler, add_handlerlogging.basicConfig(level=logging.DEBUG)logger = logging.getLogger()# A bug in Django causes the settings to load twice. Using# this handler instead of logging.addHandler works around that.add_handler(logger, DjangoDatabaseHandler())To use this handler via a logging configuration file, simply import this module in your Django settings.py before loading the configuration from a file:from djangologdb import handlerslogging.config.fileConfig(...)Then in your logging configuration file, you can add it from the handlers namespace and add it to any logger you want:keys=djangologdblevel=NOTSEThandlers=djangologdbclass=handlers.DjangoDatabaseHandlerargs=()Configuration:You can set the following settings in your Django settings.py file:LOGDB_RULES Define rules to create a new log entry when certain conditions are true. Default: LOGDB_RULES = LOGDB_LEVEL_COLORS Set colors to use in the graph for level based datasets. Default: LOGDB_LEVEL_COLORS = { logging.DEBUG: '#c2c7d1', logging.INFO: '#aad2e9', logging.WARNING: '#b9a6d7', logging.ERROR: '#deb7c1', logging.CRITICAL: '#e9a8ab', }LOGDB_MEDIA_ROOT Set the absolute path to the directory of django-logdb media. Default: LOGDB_MEDIA_URL = os.path.join(djangologdb.__path__, 'media')LOGDB_MEDIA_URL Set the URL that handles the media served from LOGDB_MEDIA_ROOT. Make sure to add a trailing slash at the end. If settings.DEBUG=True, the media will be served by Django. Default: LOGDB_MEDIA_URL = '/admin/djangologdb/media/'Commands:aggregate_logs Aggregates log entries and triggers any action with matching rules.Usage: python django-admin.py aggregate-logsOptions: -s, --skip-actions Do not use the rules to create new logs. --cleanup=CLEANUP Specifies the number of days to keep log entries and deletes the rest. Requirements: · Python · Django What's New in This Release: · Removed Django as a requirement (although it's still required) to prevent conflicts with djangorecipe.


django-logdb Related Software