Skip to main content

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

  1. Add the middleware to your framework:

For Django:

MIDDLEWARE = [
    ...
    'distributed_logger.middleware.log_middleware.AuditLogMiddleware',
]
  1. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

distributed_logger-0.1.12.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

distributed_logger-0.1.12-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file distributed_logger-0.1.12.tar.gz.

File metadata

  • Download URL: distributed_logger-0.1.12.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for distributed_logger-0.1.12.tar.gz
Algorithm Hash digest
SHA256 b0a32d6ebcc0175288f4269d09dfd8b1d5d3ba11b88cea0dd9737c00ec4506c5
MD5 e76b44ad9aa7cbe2a9ca93bd9505803d
BLAKE2b-256 2c9797ce9551afe4640669b847b2ca01ba425cfa0f3c29720c2fd0f5227a5a2b

See more details on using hashes here.

File details

Details for the file distributed_logger-0.1.12-py3-none-any.whl.

File metadata

File hashes

Hashes for distributed_logger-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 da57c659de61e75d83bad3922dc109dcd12f8666b96235e0aad938ad52a9fbd3
MD5 c6160e91735c2e05454e31aec57f32bb
BLAKE2b-256 4e567ff71d7244c1da2ed9f9d4d58d3e054b3ac2872878fe79c3297a692ac255

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page