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 parametersbucket_name
: Name of the S3 bucketlog_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.1.tar.gz
(5.2 kB
view details)
Built Distribution
File details
Details for the file s3_log_handler-0.1.1.tar.gz
.
File metadata
- Download URL: s3_log_handler-0.1.1.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06b56a2103ed8265deac27b89ba03cff72ca147b4e66f6101d4e851e749228db |
|
MD5 | 35d8529ef26d6a47c8fe98c0b05b06ad |
|
BLAKE2b-256 | 80593f3590a5f4c4cdb333e47e30a9982e04877fa7f3849d7ddb8e2fe8c58843 |
File details
Details for the file s3_log_handler-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: s3_log_handler-0.1.1-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
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbd0b07880e619b7a85b0ad6cb16d7115aff775de1e8f45566789b1edf697d39 |
|
MD5 | 0672e46b7aa06e030665fcb271f2006e |
|
BLAKE2b-256 | a6dfb1d58bb5372161423f5a71ec2509c229eabe819b7187145d78b01d73bfda |