Skip to main content

Django Decorator of Logging Request Params/Response Content

Project description

Django Decorator of Logging Request Params/Response Content

Installation

pip install django-logit

Usage

from logit import logit

@logit
def xxx(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,
        },
    },
}

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

django-logit-1.0.6.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

django_logit-1.0.6-py2.py3-none-any.whl (4.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-logit-1.0.6.tar.gz.

File metadata

File hashes

Hashes for django-logit-1.0.6.tar.gz
Algorithm Hash digest
SHA256 853087efe8590bb32e9fca3387e20cd0a38c5f91a9e0978d3273ce15ec5df6ab
MD5 ea6f2266f75cdbd744bd0a88a104a4fb
BLAKE2b-256 6567010b20a5807ac3ef526e36ff72aafbe218e6ec034514e621c87ae6b1be9a

See more details on using hashes here.

File details

Details for the file django_logit-1.0.6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_logit-1.0.6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 258553ac3a1fbdff3b4ed5d0258d3916ba8a92edfa5e996bf413ff66c7a2a72a
MD5 b6ec193719e21a2966fb5acde7987f30
BLAKE2b-256 db53731d2d3bfcd131f7a0311f37dffde69ccea165de6c508ad6fbfb42bffd5a

See more details on using hashes here.

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