A package for logging user interactions with a django distributed system.
Project description
Interaction Logger
A Django middleware for logging user interactions with your application.
Features
- Logs user activity including request and response details
- Asynchronous logging to avoid impacting request-response cycle
- Works in both ASGI and WSGI environments
- Supports custom fields for tracking additional information
Installation
pip install interaction-logger
Configuration
Add the middleware to your Django settings:
MIDDLEWARE = [
# ... other middleware
'interaction_logger.middleware.UserActivityMiddleware',
# ... other middleware
]
Usage
Basic Usage
Once configured, the middleware will automatically log user activity for all requests except those to /admin/, /static/, and /media/.
Custom Fields
You can add custom fields to track additional information. This is useful for tracking business-specific data or for debugging purposes.
from interaction_logger.middleware import UserActivityMiddleware
# Track the user's browser information
def get_browser_info(request):
user_agent = request.META.get('HTTP_USER_AGENT', '')
if 'Chrome' in user_agent:
return 'Chrome'
elif 'Firefox' in user_agent:
return 'Firefox'
else:
return 'Other'
UserActivityMiddleware.add_custom_field('browser', get_browser_info)
# Track a query parameter
UserActivityMiddleware.add_custom_field('source', lambda request: request.GET.get('source'))
The add_custom_field method takes two arguments:
field_name: The name of the custom field to trackfield_value_getter: A function that takes a request object and returns the value to track
The function should handle any exceptions internally to avoid breaking the middleware.
See the examples directory for more examples of custom fields.
Viewing Logs
User activity logs are stored in the database and can be viewed in the Django admin interface.
License
MIT
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file interaction-logger-0.3.3.tar.gz.
File metadata
- Download URL: interaction-logger-0.3.3.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ab776e4217996b813ef416a03e6d320a7eba95b873dc7a16e52d66039216b659
|
|
| MD5 |
af6c23583326f228fbaee95546968caf
|
|
| BLAKE2b-256 |
4377016feae802acee9d3e472bc4e9ff35793520e354f95ed12ca50f44e53ee0
|
File details
Details for the file interaction_logger-0.3.3-py3-none-any.whl.
File metadata
- Download URL: interaction_logger-0.3.3-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9381a6aed345b9fd8560c3861ccd934e9cd0c7edc0f90671e43d9c47f6f23bf
|
|
| MD5 |
19f06e7854c0cacb047e39dced729020
|
|
| BLAKE2b-256 |
3385348ddbc218d1bbce19c9ee100f50f5f256fbb052806ff968009ca051b09f
|