A versatile logging package with async support
Project description
ai_logstash
A versatile logging package that supports both synchronous and asynchronous logging in Python, with Logstash integration for centralized log management and monitoring.
Features
- Supports both synchronous and asynchronous logging
- Integrates seamlessly with Logstash
- Masks sensitive information automatically
- Provides decorators for automatic exception logging
- Includes environment variables and local variables in logs
- Compatible with various Python applications, including FastAPI and Aiogram
Installation
Using pipenv (recommended)
[packages]
pipenv install ai_logstash
Using pip
pip install ai_logstash
Usage
Synchronous Logging
from ai_logstash import SyncAiLogger, sync_log_exception
logger = SyncAiLogger(
'my-service',
project_name="work_wallet",
masked_variables_names=["PRIVATE", "password", "api_key"],
logstash_host="logstash.example.com",
logstash_port=5000,
container_tag="1.0",
environment="production"
)
@sync_log_exception(logger)
def my_function():
logger.info("Starting my_function")
# Your code here
Asynchronous Logging (e.g., for FastAPI or Aiogram)
from ai_logstash import AsyncAiLogger, create_async_error_handler
logger = AsyncAiLogger(
'my-async-service',
project_name="work_wallet",
masked_variables_names=["PRIVATE", "password", "api_key"],
logstash_host="logstash.example.com",
logstash_port=5000,
container_tag="1.0",
environment="production"
)
errors_handler = create_async_error_handler(logger)
@errors_handler
async def my_async_function():
await logger.info("Starting my_async_function")
# Your async code here
Configuration
service_name
: Name of your serviceproject_name
: Name of your project (work_wallet, payout_bot, etc.)masked_variables_names
: List of sensitive variable names to be maskedlogstash_host
: Hostname of your Logstash serverlogstash_port
: Port of your Logstash servercontainer_tag
: Tag for container versionenvironment
: Deployment environment (e.g., "production", "development")log_level
: Logging level (default: "INFO")
Benefits
- Centralized logging with Logstash integration
- Automatic masking of sensitive information
- Easy integration with various Python frameworks
- Supports both synchronous and asynchronous applications
- Includes detailed error information and environment variables
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
ai_logstash-0.6.0.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for ai_logstash-0.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75aa3d0ed81c5d349b2112d19e0eafe62aaea1d38a4b6e2e91eb43eee6b761e3 |
|
MD5 | 2bc06422dd547c9d7c36a1dd4604ba14 |
|
BLAKE2b-256 | 1376955cfa27b0c44f727269e37581fa31f7c8b112dd6924a1aada0173f96689 |