
Security News
Official Go SDK for MCP in Development, Stable Release Expected in August
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
django-logging-middleware
Advanced tools
The extension for django to log requests and responses using loguru.
Sometimes code in django views becomes messy because we log requests and response. Also it takes a lot of time to write logs in every view. Using this extension for django, logging becomes simple: all you need is five minutes of installing this package and setting configuration!
Install using pip
...
pip install django-logging-middleware
Add 'logging_middleware'
to your INSTALLED_APPS
setting.
INSTALLED_APPS = [
...
'logging_middleware'
]
Add setting in your settings.py
:
DJANGO_LOGGING_MIDDLEWARE = {
'DEFAULT_FORMAT': False,
'MESSAGE_FORMAT': "<b><green>{time}</green> <cyan>{message}</cyan></b>"
}
Add 'logging_middleware.middlewares.DjangoLoggingMiddleware'
to your MIDDLEWARE
setting.
MIDDLEWARE = {
...
'logging_middleware.middlewares.DjangoLoggingMiddleware'
}
Note 'logging_middleware.middlewares.DjangoLoggingMiddleware'
should be last in the list MIDDLEWARE
You are ready to see log messages like ones below!
...
2021-01-08T23:39:33.597138 Request URL: http://localhost:8000/restframework/simple/class/with_query_string/?data=data
2021-01-08T23:39:33.597530 Request METHOD: PUT
2021-01-08T23:39:33.597874 Request HEADERS: {'Cookie': '', 'Content-Length': '26', 'Content-Type': 'application/json'}
...
If you missed 4th step in installation, default settings would be:
DJANGO_LOGGING_MIDDLEWARE = {
'DEFAULT_FORMAT': True,
'MESSAGE_FORMAT': "<b><green>{time}</green> <cyan>{message}</cyan></b>"
}
'DEFAULT_FORMAT'
'DEFAULT_FORMAT'
by default is True
. It means middleware will use default string format for log messages. By setting it to False
, you should provide in 'MESSAGE_FORMAT'
your own string format.
'MESSAGE_FORMAT'
'MESSAGE_FORMAT'
sets the format of log messages. By default is '<b><green>{time}</green> <cyan>{message}</cyan></b>'
. For making your own format string, please look the loguru docs. Note if you set 'DEFAULT_FORMAT'
as True
, but also set custom string format in 'MESSAGE_FORMAT'
, the log messages will take the default format. Also by setting 'DEFAULT_FORMAT'
as False without providing the 'MESSAGE_FORMAT'
, the format of messages will be default.
MIT-License, see LICENSE file.
FAQs
A small package to log django requests and responses
We found that django-logging-middleware demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.
Security News
New research reveals that LLMs often fake understanding, passing benchmarks but failing to apply concepts or stay internally consistent.
Security News
Django has updated its security policies to reject AI-generated vulnerability reports that include fabricated or unverifiable content.