Skip to content

Logger for the logging module that writes messages to the database

License

Notifications You must be signed in to change notification settings

mnemchinov/django-logging-eventlog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Python version Django version

django-logging-eventlog

Logger for the logging module that writes messages to the django database

http://www.mnemchinov.ru/images/projects/django-logging-eventlog/eventlog_events.jpg

http://www.mnemchinov.ru/images/projects/django-logging-eventlog/eventlog_event_exception.jpg

Installation

  1. Install using pip:

    pip install --upgrade django-logging-eventlog
    
  2. Modify your settings.py. Add eventlog to your INSTALLED_APPS:

    INSTALLED_APPS = [
        #django apps
        'eventlog',
        #your apps
    ]
    
  3. Configure LOGGING in your settings.py for example:

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'handlers': {
            'eventlog': {
                'class': 'eventlog.services.EventLogHandler'
            },
            'console': {
                'class': 'logging.StreamHandler',
            },
        },
        'loggers': {
            'root': {
                'handlers': ['console', 'eventlog'],
                'level': 'INFO',
                'propagate': True,
            },
        }
    }
    
  4. Run python manage.py makemigrations eventlog and run Run python manage.py migrate

Usage

import logging

logger = logging.getLogger(__name__)
logger.info('info')
logger.debug('debug')
logger.error('error')
logger.critical('critical')
logger.warning('warning')

try:
    1/0

except Exception as ex:
    logger.exception(ex, exc_info=ex)

To prune the eventlog, use the command as pruneeventlog. For example, to keep records in the database only for the last 30 days, run:

python manage.py pruneeventlog 30

About

Logger for the logging module that writes messages to the database

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages