A lightweight logging system with Kafka support for auditing and debugging
Project description
Distributed Logger
A lightweight logging system with Kafka support for auditing and debugging. Provides middleware for request auditing that can be used with any WSGI/ASGI framework.
Features
- Request auditing middleware
- Support for multiple logging backends:
- Kafka
- Simple console logging
- (More backends coming soon)
- Simple environment-based configuration
- Framework agnostic (works with Django, Flask, FastAPI, etc.)
Installation
pip install distributed-logger
Quick Start
- Add the middleware to your framework:
For Django:
MIDDLEWARE = [
...
'distributed_logger.middleware.log_middleware.AuditLogMiddleware',
]
- Set environment variables for configuration:
# For Kafka logging
export BROKER_TYPE=KAFKA
export KAFKA_BOOTSTRAP_SERVERS=localhost:9092
export KAFKA_TOPIC=audit_logs
export KAFKA_CLIENT_ID=your_app_name
# For simple console logging
export BROKER_TYPE=SIMPLE
That's it! The middleware will automatically log all requests.
Usage Examples
Custom Logging
from distributed_logger.loggers import KafkaLogger
from distributed_logger.models import LogInfo
from distributed_logger.models.config import KafkaConfig
# Create a logger instance
config = KafkaConfig(
broker_type="KAFKA",
bootstrap_servers=["localhost:9092"],
topic="audit_logs"
)
logger = KafkaLogger(config=config)
# Log some information
log_info = LogInfo(
ip_address="127.0.0.1",
user_id="user123",
request_time="2024-01-01 12:00:00",
action="custom_action",
request_data={"key": "value"}
)
logger.publish(log_info)
Environment Variables
| Variable | Description | Default |
|---|---|---|
| BROKER_TYPE | Type of logging backend ('KAFKA' or 'SIMPLE') | 'SIMPLE' |
| KAFKA_BOOTSTRAP_SERVERS | Comma-separated list of Kafka brokers | 'localhost:9092' |
| KAFKA_TOPIC | Kafka topic for logs | 'audit_logs' |
| KAFKA_CLIENT_ID | Client ID for Kafka producer | None |
Development
To set up for development:
# Clone the repository
git clone https://github.com/arjun-navya/distributed-logger.git
cd distributed-logger
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details. # logger
Project details
Release history Release notifications | RSS feed
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 distributed_logger-0.1.10.tar.gz.
File metadata
- Download URL: distributed_logger-0.1.10.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7636a84da75e2e2aa66cf0d0b6709c6c3d16a9d8c5816c756dfd0d38c0e6af53
|
|
| MD5 |
b832103305c15e6dd9e3beb7df1ab232
|
|
| BLAKE2b-256 |
4115d23f6d70f6cbdb5e6333c62825b57b7d08da623c035f3d5afecb0042dc14
|
File details
Details for the file distributed_logger-0.1.10-py3-none-any.whl.
File metadata
- Download URL: distributed_logger-0.1.10-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3dc0cb19c258367e4791a7f3156864ad26e15d27ee33e639afe6421cb0ea9057
|
|
| MD5 |
7c61ceea1503fa3cf8013cde11f0f4a0
|
|
| BLAKE2b-256 |
3c562d4f5111d0f418e8ce89ca42fc184e9a36f3b697cfa16cfe99f5878351ce
|