This is a pre-production deployment of Warehouse, however changes made here WILL affect the production instance of PyPI.
Latest Version Dependencies status unknown Test status unknown Test coverage unknown
Project Description

A python logging handler that saves logs into django model. That’s it.

Installation

Via pip:

pip install django-modelhandler

Usage

Add modelhandler to your INSTALLED_APPS, then, configure log handler in your desired way. For example, using dictConfig:

{
    'version': 1,
    'handlers': {
        'modelhandler': {
            'class': 'modelhandler.handlers.LogModel',
            'level': 'ERROR'
        }
    },
    'loggers': {
        'my_logger': {
            'handlers': ['modelhandler'],
            'level': 'ERROR'
        }
    }
}

Run migrations that will create a Log model:

python manage.py migrate

And now you can start logging in django model.

Getting logs:

from modelhandler.models import Log
# Get the latest log
log = Log.objects.latest()
log.name # logger name
log.level # logging level integer
log.levelname # logging level as string (DEBUG, INFO, etc.)
log.message # the log message
log.traceback # traceback, if exists. default: None
log.filename # filename (with ext) where the log was sent
log.funcName # function name where the log was sent
log.created # log creation datetime
log.formatted # the log message as if it was written in file. (with [datetime] [level] etc.)

If you have a django admin enabled, then you can browse your logs on model Log of application modelhandler. It has a customized modeladmin to enabale filtering by logger name and levelname, and searching by message.

If you would like to customize a log model (to alter models Meta), then just subclass a modelhandler.models.Log model, do whatever you want and add your model to LogModel handler parameters:

'handlers': {
    'modelhandler': {
        'class': 'modelhandler.handlers.LogModel',
        'model': 'path.to.your.model'
        'level': 'ERROR'
    }
}

If you using celery in your project then you might want to add some model cleaning tasks in CELERYBEAT_SCHEDULE:

CELERYBEAT_SCHEDULE = {
    'cleanup_day': {
        'task': 'modelhandler.tasks.cleanup_day',
        'schedule': timedelta(days=1)
    }, # OR
    'cleanup_week': {
        'task': 'modelhandler.tasks.cleanup_week',
        'schedule': timedelta(days=7)
    }, # OR
    'cleanup_month': {
        'task': 'modelhandler.tasks.cleanup_month',
        'schedule': timedelta(days=30)
    }
}

modelhandler.tasks.cleanup_day will delete all logs that are older than one day from time of task execution. modelhandler.tasks.cleanup_week and modelhandler.tasks.cleanup_month are similar.

If you want to customize the time of deletion, there is a task modelhandler.tasks.cleanup_logs that accepts a before parameter that must be a datetime object or None (in this case a value of timezone.now() will be taken). There is no magic: just Log.objects.filter(created__lte=before).delete()

History

1.0.0 (2016-06-12)

  • Initial release
Release History

Release History

1.0.0

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

TODO: Brief introduction on what you do with files - including link to relevant help section.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-modelhandler-1.0.0.zip (6.6 kB) Copy SHA256 Checksum SHA256 Source Jun 15, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS HPE HPE Development Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting