Skip to main content

Django helper app for logging ID.

Project description

https://travis-ci.org/mmiyajima2/django-kantanlog.svg?branch=master https://coveralls.io/repos/github/mmiyajima2/django-kantanlog/badge.svg?branch=master

Kantan log is a simple Django helper app. This app supports logging to Django Model’s created_by, updated_by. At http requests interception, too.

Installation

shell>pip install djangokantanlog

Usage

Installed apps:

INSTALLED_APPS = [
  ...
  'kantanlog.apps.KantanlogConfig',
]

Middleware:

MIDDLEWARE = [
  ...
  'kantanlog.middlewares.KantanlogMiddleware',
]

Settings

KLOG_TARGET_APP_LABELS

Default: ()

Target apps, settings as app-label:

KLOG_TARGET_APP_LABELS = (
  ...
  'myapp',
)

KLOG_BACKEND

Default: kantanlog.backends.KantanlogDefaultBackend

As interface, getting user.

e.g.

# at settings.py
KLOG_BACKEND = 'dotted.path.to.MyappBackend'

...

# -*- coding: utf8 -*-
from logging import getLogger
from kantanlog.backends import KantanlogDefaultBackend
from rest_framework_jwt.authentication import JSONWebTokenAuthentication
from rest_framework_jwt.settings import api_settings


logger = getLogger(__name__)
payload_handler = api_settings.JWT_PAYLOAD_HANDLER
encode_handler = api_settings.JWT_ENCODE_HANDLER


class MyappBackend(KantanlogDefaultBackend):

    def __init__(self):
        super().__init__()

    def get_user(self, request):
        user = super().get_user(request)
        if user.is_authenticated:
            return user
        ja = JSONWebTokenAuthentication()
        if ja.get_jwt_value(request):
            user, jwt = ja.authenticate(request)
            return user
        return user

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangokantanlog-0.0.4.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

djangokantanlog-0.0.4-py3-none-any.whl (9.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page