A Django middleware for logging HTTP requests and responses.
Project description
Django Access Logger
Django Access Logger is a middleware for logging HTTP requests and responses in Django applications. It supports logging to files, SQL databases, and NoSQL databases.
Features
- Log HTTP requests and responses
- Support for file, SQL, and NoSQL logging
- Configurable via Django settings
- Compatible with django-tenants
- Supports separate database for logging
Installation
Install the package using pip:
pip install dj-access-logger
Configuration
Add the middleware to your Django settings:
# settings.py
INSTALLED_APPS = [
...
'dj_access_logger'
...
]
MIDDLEWARE = [
...
'dj_access_logger.middleware.AccessLoggerMiddleware',
...
]
# Logging configuration
DJ_ACCESS_LOGGER = {
'method': 'file', # 'file' or 'sql' or 'nosql'
'separated_logging_db': True,
'obfuscate_secrets': True,
'logging_db_parameters': {
'ENGINE': 'django.db.backends.mysql', # Use 'djongo' for MongoDB
'NAME': 'logging_db',
'USER': 'logging_user',
'PASSWORD': 'logging_password',
'HOST': 'localhost',
'PORT': '3306',
'NOSQL_HOST': 'mongodb://localhost:27017', # NoSQL specific parameter
}
}
# If using a separate logging database, add this to your DATABASE_ROUTERS
DATABASE_ROUTERS = [
...,
'dj_access_logger.db_router.LoggingDBRouter',
...
]
Setup
After changing your settings.py you need to run the following commands to create the necessary tables in the logging database:
python manage.py setup_dj_access_logger
Usage
The middleware will automatically log HTTP requests and responses based on the configuration.
Documentation
For detailed documentation, visit Read the Docs.
License
This project is licensed under the MIT License.
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
Built Distribution
File details
Details for the file dj-access-logger-1.0.5.tar.gz
.
File metadata
- Download URL: dj-access-logger-1.0.5.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52dd9f9b7c96ea8c1dcc70c4f3f03329f2f3879120d6489ae681c412ad1b6371 |
|
MD5 | d5337bda46d44760ca941de60842d5dc |
|
BLAKE2b-256 | 3ccd4650e40358273875fb38e6e216f595a9de6b5b89efbe77a29e8b0d1eead6 |
File details
Details for the file dj_access_logger-1.0.5-py3-none-any.whl
.
File metadata
- Download URL: dj_access_logger-1.0.5-py3-none-any.whl
- Upload date:
- Size: 15.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e2a1d94ef54f5a6c9608661203fb443fa49a074269898b4ffd78ead16f00950 |
|
MD5 | 1e5482dbb8a9190c5f5b07cda626d0a7 |
|
BLAKE2b-256 | 4114097b7348ac3e80ae01a10d584ce2f987350cddc641cee30f77820fa98cf3 |