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 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,
        },
    },
}

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.1.3.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

django_logit-1.1.3-py2.py3-none-any.whl (3.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

File hashes

Hashes for django-logit-1.1.3.tar.gz
Algorithm Hash digest
SHA256 af158a94ac7795b50d7ef64ab5774f261824feed4638b4be03960bf243287ac5
MD5 db752f951ce392ba3f23709fed90416d
BLAKE2b-256 22031cf0d0f80f867c4e679f60226d38f81d9e5cae0850f0241f09a34a146bb9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_logit-1.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a6048604414e32993a92c95fdf7ffa2143b13c5122402ed72cb3b61c9b3513eb
MD5 c7d4352cedb6062a76a4c7b9f27206e6
BLAKE2b-256 26767a72838b14ef867c5a627ec537260e689c19ff33e3c24f84645a24efc032

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