GithubHelp home page GithubHelp logo

guoyu07 / django-simple-log Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kindlycat/django-simple-log

0.0 0.0 0.0 110 KB

Logging django models changes

License: Other

Makefile 0.15% Python 95.50% HTML 4.35%

django-simple-log's Introduction

Django simple log

https://travis-ci.org/kindlycat/django-simple-log.svg?branch=master https://coveralls.io/repos/github/kindlycat/django-simple-log/badge.svg?branch=master

Logging model changes on every create/update/delete.

TL;DR

Install using pip:

$ pip install django-simple-log

Add to installed apps:

INSTALLED_APPS = (
    ...
    'simple_log',
    ...
)

Add middleware for detecting user:

MIDDLEWARE = [
    ...
    'simple_log.middleware.ThreadLocalMiddleware',
    ...
]

For django 1.8:

$ pip install django-jsonfield django-transaction-hooks
DATABASES = {
    'default': {
        'ENGINE': 'transaction_hooks.backends.postgresql_psycopg2',
        ...
    }
}

Migrate:

$ python manage.py migrate

Disable logging

For temporary disable logging:

from simple_log.utils import disable_logging

with disable_logging():
    # create/update/delete objects

Commands

To view which models is tracking:

$ python manage.py view_tracking_models

With option -f you can view which fields is tracking for every model.

Settings

SIMPLE_LOG_MODEL_LIST

Default: ()

List of models for logging by label: 'app.Model'.

SIMPLE_LOG_EXCLUDE_MODEL_LIST

Default: ('admin.LogEntry', 'migrations.Migration', 'sessions.Session', 'contenttypes.ContentType', 'captcha.CaptchaStore')

List of models for exclude from logging by label: 'app.Model'.

SIMPLE_LOG_EXCLUDE_FIELD_LIST

Default: ('id', 'last_login', 'password', 'created_at', 'updated_at')

List of field names which not track.

If you need to define which fields to track for concrete model, you can add one of the properties to model: simple_log_fields = ('id',) or simple_log_exclude_fields = ('password',).

SIMPLE_LOG_ANONYMOUS_REPR

Default: 'Anonymous'

User representation that write to log, if anonymous user changes model.

SIMPLE_LOG_NONE_USER_REPR

Default: 'System'

User representation that write to log, if user not detected (If middleware not working or if model changes from task or console).

SIMPLE_LOG_MODEL

Default: 'simple_log.SimpleLog'

Model for writing logs. If you want to define your own model, you should inheritance from simple_log.SimpleLogAbstract and change this setting.

SIMPLE_LOG_MODEL_SERIALIZER

Default: 'simple_log.models.ModelSerializer'

Class for serializing model fields to json.

SIMPLE_LOG_GET_CURRENT_REQUEST

Default: 'simple_log.utils.get_current_request_default'

Function that return current request. Rewrite this setting if you already have middleware for storing current request.

SIMPLE_LOG_OLD_INSTANCE_ATTR_NAME

Default: '_old_instance'

Name of attribute for storing old instance of logging object.

django-simple-log's People

Contributors

kindlycat 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.