Git Product home page Git Product logo

django-request-logging's Introduction

django-request-logging

Plug django-request-logging into your Django project and you will have intuitive and color coded request/response payload logging, for both web requests and API requests

Installing

$ pip install django-request-logging

Then add request_logging.middleware.LoggingMiddleware to your MIDDLEWARE.

For example:

MIDDLEWARE = (
    ...,
    'request_logging.middleware.LoggingMiddleware',
    ...,
)

And configure logging in your app:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
        },
    },
    'loggers': {
        'django.request': {
            'handlers': ['console'],
            'level': 'DEBUG',  # change debug level as appropiate
            'propagate': False,
        },
    },
}

Details

Most of times you don't have to care about these details. But in case you need to dig deep:

  • All logs are configured using logger name "django.request".
  • If HTTP status code is between 400 - 599, URIs are logged at ERROR level, otherwise they are logged at INFO level.
  • If HTTP status code is between 400 - 599, data are logged at ERROR level, otherwise they are logged at DEBUG level.

A no_logging decorator is included for views with sensitive data.

Django settings

You can customized some behaves of django-request-logging by following settings in Django settings.py.

REQUEST_LOGGING_DATA_LOG_LEVEL

By default, data will log in DEBUG level, you can change to other valid level (Ex. logging.INFO) if need.

REQUEST_LOGGING_ENABLE_COLORIZE

If you want to log into log file instead of console, you may want to remove ANSI color. You can set REQUEST_LOGGING_ENABLE_COLORIZE=False to disable colorize.

REQUEST_LOGGING_DISABLE_COLORIZE (Deprecated)

This legacy setting will still available, but you should't use this setting anymore. You should use REQUEST_LOGGING_ENABLE_COLORIZE instead. We keep this settings for backward compatibility.

REQUEST_LOGGING_MAX_BODY_LENGTH

By default, max length of a request body and a response content is cut to 50000 characters.

Enjoy!

Email me with any questions: [email protected].

django-request-logging's People

Contributors

bashu avatar calvin620707 avatar devkral avatar kennethjiang avatar manelclos avatar meschbach avatar pdaw avatar pmdarrow avatar raja-creoit avatar raja27 avatar rbruggem avatar singleton11 avatar steven-lee-qadium avatar tclancy 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.