Skip to main content

A Python logging handler that uploads logs to Amazon S3

Project description

S3 Log Handler

A Python logging handler that asynchronously uploads logs to Amazon S3 in batches.

Features

  • Asynchronous upload to S3 using aioboto3
  • Batching of log messages for efficient uploading
  • Automatic compression of logs using gzip
  • Configurable batch size and flush intervals
  • Thread-safe operation
  • Graceful shutdown handling with proper cleanup

Installation

pip install s3-log-handler

Usage

import logging
from s3_log_handler import S3LogHandler

# Configure AWS credentials
client_params = {
    "aws_access_key_id": "your_access_key",
    "aws_secret_access_key": "your_secret_key",
    "region_name": "your_region"
}

# Create and configure the handler
handler = S3LogHandler(
    client_params=client_params,
    bucket_name="your-bucket-name",
    log_prefix="application-logs",
    batch_size=100,
    flush_interval=300
)

# Add handler to logger
logger = logging.getLogger()
logger.addHandler(handler)

# Log messages will now be uploaded to S3
logger.info("Hello, S3!")

Configuration

  • client_params: Dictionary of AWS client parameters
  • bucket_name: Name of the S3 bucket
  • log_prefix: Prefix for S3 keys (default: "application-logs")
  • batch_size: Number of logs to batch before upload (default: 100)
  • flush_interval: Maximum seconds between uploads (default: 300)

License

MIT License - see LICENSE file for details

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

s3_log_handler-0.1.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

s3_log_handler-0.1.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file s3_log_handler-0.1.3.tar.gz.

File metadata

  • Download URL: s3_log_handler-0.1.3.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/23.5.0

File hashes

Hashes for s3_log_handler-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7e02059e9826b003d197562e0bcd74d0a44b3c3cf32ed89e630cad9d9caf5aef
MD5 7a2f696f1698e90d3357cb7952f2c953
BLAKE2b-256 a756e81a749941cc5bb95a6550392d33334d1e9bef200a87a847ef4b071072ce

See more details on using hashes here.

File details

Details for the file s3_log_handler-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: s3_log_handler-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/23.5.0

File hashes

Hashes for s3_log_handler-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 450e524ec53d5c5456a04537f635097aa9cdfd1065aa67884ee84b1f317c6055
MD5 a66e6a3d529fd49c0a18a2763b4ecc10
BLAKE2b-256 25886972ecbeb8f1cfbdd20bff46fb28c5d903d868517a97a92ddd0d64200213

See more details on using hashes here.

Supported by

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