A middleware to log the requests and responses using loguru.

Related tags

Djangodjango-loguru
Overview

Django Loguru

The extension was based on another one and added some extra flavours. One of the biggest problems with the apps is the logging and that can be messy sometimes.

Since this serves as a middleware, it only depends on django (including django rest framework).

Documentation: https://tarsil.github.io/django-loguru/

Table of Contents


  1. Requirements
  2. Installation
  3. Settings
  4. License

Requirements

  1. Python >= 3.7
  2. Django >= 3.1

Installation

  • pip install django-loguru
  • Add django_loguru to INSTALLED_APPS settings.
INSTALLED_APPS = [
    ...
    'django_loguru'
]
  • Add DJANGO_LOGURU_MIDDLEWARE to your settings.
{time} {message} ", 'LOG_USER': False } ">
DJANGO_LOGGING_MIDDLEWARE = {
    'DEFAULT_FORMAT': True,
    'MESSAGE_FORMAT': "
    
     {time}
     
    
     {message}
    ",
    'LOG_USER': False
}
  • Add django_loguru.middleware.DjangoLoguruMiddleware as the very last in the list of MIDDLEWARE.

The logs should be now activated for every request/response of you application.

If you desire to override what is shown on the screen.

from django_loguru.middleware import DjangoLoguruMiddleware

class MyCustomMiddleware(DjangoLoguruMiddleware):

    def __call__(self, request):
        """
        Code to be executed on every request/response call.
        """
        logger.info(f"URL: {request.get_raw_uri()}")
        logger.info(f"Method: {request.method}")
        ...
        ...

Settings

  1. DEFAULT_FORMAT - Default True and it will use the default MESSAGE_FORMAT.
  2. MESSAGE_FORMAT - Sets the format of the log messages. Defaults to {time} {message} . More information about your options on loguru docs.
  3. LOG_POST - Default to False and it won't show POST data.
  4. LOG_PUT - Default to False and it won't show PUT data.
  5. LOG_PATCH - Default to False and it won't show PATCH data.
  6. LOG_DELETE - Default to False and it won't show DELETE data.
  7. LOG_USER - Default to True and tells which user did the request/response.

License

MIT-License

Owner
Tiago Silva
Entrepreneur, fully minded and dedicated software engineer with strong backend background and leadership skills.
Tiago Silva
Wagtail - Vue - Django : The initial environment of full-stack local dev web app with wagtail and vue

Wagtail - Vue - Django : The initial environment of full-stack local dev web app with wagtail and vue. A demo to show how to use .vue files inside django app.

Quang PHAM 2 Oct 20, 2022
Django Serverless Cron - Run cron jobs easily in a serverless environment

Django Serverless Cron - Run cron jobs easily in a serverless environment

Paul Onteri 41 Dec 16, 2022
Analytics services for Django projects

django-analytical The django-analytical application integrates analytics services into a Django project. Using an analytics service with a Django proj

Jazzband 1.1k Dec 31, 2022
A starter template for building a backend with Django and django-rest-framework using docker with PostgreSQL as the primary DB.

Django-Rest-Template! This is a basic starter template for a backend project with Django as the server and PostgreSQL as the database. About the templ

Akshat Sharma 11 Dec 06, 2022
Custom Django field for using enumerations of named constants

django-enumfield Provides an enumeration Django model field (using IntegerField) with reusable enums and transition validation. Installation Currently

5 Monkeys 195 Dec 20, 2022
An insecure login and registration website with Django.

An insecure login and registration website with Django.

Luis QuiƱones Requelme 1 Dec 05, 2021
Agenda feita usando o django para adicionar eventos

Agenda de Eventos Projeto Agenda com Django Inicio O projeto foi iniciado no Django, usando o models.py foi adicionado os dados dos eventos e feita as

Bruno Fernandes 1 Apr 14, 2022
This is raw connection between redis server and django python app

Django_Redis This repository contains the code for this blogpost. Running the Application Clone the repository git clone https://github.com/xxl4tomxu9

Tom Xu 1 Sep 15, 2022
Returns unicode slugs

Python Slugify A Python slugify application that handles unicode. Overview Best attempt to create slugs from unicode strings while keeping it DRY. Not

Val Neekman (AvidCoder) 1.3k Dec 23, 2022
Inject an ID into every log message from a Django request. ASGI compatible, integrates with Sentry, and works with Celery

Django GUID Now with ASGI support! Django GUID attaches a unique correlation ID/request ID to all your log outputs for every request. In other words,

snok 300 Dec 29, 2022
Django Rest Framework + React application.

Django Rest Framework + React application.

2 Dec 19, 2022
Domain-driven e-commerce for Django

Domain-driven e-commerce for Django Oscar is an e-commerce framework for Django designed for building domain-driven sites. It is structured such that

Oscar 5.6k Jan 01, 2023
The new Python SDK for Sentry.io

Bad software is everywhere, and we're tired of it. Sentry is on a mission to help developers write better software faster, so we can get back to enjoy

Sentry 1.4k Jan 05, 2023
Django React Flight Rezervation

Django Intro & Installation python -m venv venv source ./venv/Scripts/activate pip install Django pip install djangorestframework pip install python-d

HILMI SARIOGLU 2 May 26, 2022
Fully reponsive Chat Application built with django, javascript, materialUi, bootstrap4, html and css.

Chat app (Full Stack Frameworks with Django Project) Fully reponsive Chat Application built with django, javascript, materialUi, bootstrap4, html and

1 Jan 19, 2022
E-Commerce Platform

Shuup Shuup is an Open Source E-Commerce Platform based on Django and Python. https://shuup.com/ Copyright Copyright (c) 2012-2021 by Shuup Commerce I

Shuup 2k Jan 07, 2023
This is a basic Todo Application API using Django Rest Framework

Todo Application This is a basic Todo Application API using Django Rest Framework. Todo Section - User can View his previously added todo items, creat

Atharva Parkhe 1 Aug 09, 2022
Source code for Django for Beginners 3.2

The official source code for https://djangoforbeginners.com/. Available as an ebook or in Paperback. If you have the 3.1 version, please refer to this

William Vincent 10 Jan 03, 2023
:couple: Multi-user accounts for Django projects

django-organizations Summary Groups and multi-user account management Author Ben Lopatin (http://benlopatin.com / https://wellfire.co) Status Separate

Ben Lopatin 1.1k Jan 01, 2023
Faker is a Python package that generates fake data for you.

Faker is a Python package that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in yo

Daniele Faraglia 15.2k Jan 01, 2023