django-logit 1.1.4
Django Decorator of Logging Request Params/Response Content
Keywords: Django Logging Log POST GET Query Params

============
django-logit
============

Django Decorator of Logging Request Params/Response Content

Installation
============

::

    pip install django-logit


Usage
=====

::

    from django_logit import logit

    @logit
    def xxx(request):
        xxx

    @logit(body=True, res=True)
    def ooo(request):
        xxx


Settings.py
===========

::

    # logger setting
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'verbose': {
                'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
            },
            'simple': {
                'format': '%(levelname)s %(message)s'
            },
        },
        'handlers': {
            'logit': {
                'level': 'DEBUG',
                'class': 'logging.FileHandler',
                'filename': '/tmp/logit.log',
                'formatter': 'verbose'
            },
        },
        'loggers': {
            'logit': {
                'handlers': ['logit'],
                'level': 'DEBUG',
                'propagate': True,
            },
        },
    }


ConcurrentLogHandler::

    Use RotatingFileHandler/TimedRotatingFileHandler ``Logs Missing`` when host in uwsgi with multiple process
    Use ConcurrentLogHandler Instead
    Concurrent logging handler (drop-in replacement for RotatingFileHandler) Python 2.6+.
    This module provides an additional log handler for Python’s standard logging package (PEP 282). This handler will write log events to log file which is rotated when the log file reaches a certain size. Multiple processes can safely write to the same log file concurrently.
    Installation: pip install ConcurrentLogHandler

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'verbose': {
                'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
            },
            'simple': {
                'format': '%(levelname)s %(message)s'
            },
        },
        'handlers': {
            'logit': {
                'level': 'DEBUG',
                'class': 'logging.handlers.ConcurrentRotatingFileHandler',
                'filename': '/tmp/logit.log',
                'maxBytes': 15728640,  # 1024 * 1024 * 15B = 15MB
                'backupCount': 10,
                'formatter': 'verbose',
            },
        },
        'loggers': {
            'logit': {
                'handlers': ['logit'],
                'level': 'DEBUG',
                'propagate': True,
            },
        },
    }


RotatingFileHandler::

    Use RotatingFileHandler to support rotation of disk log files.

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'verbose': {
                'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
            },
            'simple': {
                'format': '%(levelname)s %(message)s'
            },
        },
        'handlers': {
            'logit': {
                'level': 'DEBUG',
                'class': 'logging.handlers.RotatingFileHandler',
                'filename': '/tmp/logit.log',
                'maxBytes': 15728640,  # 1024 * 1024 * 15B = 15MB
                'backupCount': 10,
                'formatter': 'verbose',
            },
        },
        'loggers': {
            'logit': {
                'handlers': ['logit'],
                'level': 'DEBUG',
                'propagate': True,
            },
        },
    }


TimedRotatingFileHandler::

    Use TimedRotatingFileHandler to support rotation of disk log files at certain timed intervals.

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'formatters': {
            'verbose': {
                'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
            },
            'simple': {
                'format': '%(levelname)s %(message)s'
            },
        },
        'handlers': {
            'logit': {
                'level': 'DEBUG',
                'class': 'logging.handlers.TimedRotatingFileHandler',
                'filename': '/tmp/logit.log',
                'when': 'midnight',
                'backupCount': 10,
                'formatter': 'verbose',
            },
        },
        'loggers': {
            'logit': {
                'handlers': ['logit'],
                'level': 'DEBUG',
                'propagate': True,
            },
        },
    }