app-logs-ai
Python SDK for AI Application Logs. Batches log entries and ships them to the ingest API.
Install
pip install app-logs-ai
Quick Start
from app_logs_ai import create_logger
logger = create_logger({
"api_key": "your-api-key-here",
})
logger.info("Server started", {"port": 8000})
logger.error("Database connection failed", {"error": "ECONNREFUSED"})
Configuration
Options passed to create_logger():
api_key(required): Your project's API keyendpoint: Ingest endpoint URL (defaults to https://api-app-logs.up.railway.app/v1/ingest)batch_size: Flush when this many entries are buffered (default: 20)flush_interval_ms: Flush at most this often in milliseconds (default: 2000)source: Logical source label (default: "backend")max_buffer_size: Max entries kept in memory (default: 10000)max_retries: Send attempts per flush before re-queueing (default: 4)retry_backoff_ms: Base delay for exponential backoff (default: 500)gzip_threshold: Compress payloads larger than this (bytes, 0 to disable, default: 1024)persist_path: File path for crash-durable buffering (optional)flush_on_exit: Auto-flush on SIGTERM/SIGINT (default: True)fallback_to_stderr: Print undelivered logs to stderr (default: True)enable_metrics_heartbeat: Send periodic metrics (default: True)metrics_heartbeat_ms: Metrics interval in milliseconds (default: 15000)
Log Levels
The logger supports these levels:
debug(message, attributes)info(message, attributes)warn(message, attributes)error(message, attributes)fatal(message, attributes)
The generic log(level, message, attributes) method is also available.
Durability
- Batching: Entries are buffered and sent every 2 seconds or when 20 entries accumulate
- Retries: Failed sends are retried with exponential backoff
- Persistence: With
persist_pathset, undelivered entries survive process restarts - Graceful shutdown: Automatic flush on exit; call
logger.flush()to ensure delivery
Example with FastAPI
See examples/fastapi-app/ for a complete example application.
from fastapi import FastAPI
from app_logs_ai import create_logger
import os
app = FastAPI()
logger = create_logger({"api_key": os.environ.get("APP_LOGS_KEY", "test-key")})
@app.get("/api/users")
async def get_users():
logger.info("Fetching users", {"endpoint": "/api/users"})
return {"users": []}
@app.exception_handler(Exception)
async def exception_handler(request, exc):
logger.error("Unhandled exception", {
"path": str(request.url),
"error": str(exc),
})
return {"error": str(exc)}
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
app_logs_ai-0.1.1.tar.gz
(5.3 kB
view details)
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 app_logs_ai-0.1.1.tar.gz.
File metadata
- Download URL: app_logs_ai-0.1.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3143545fefb976f8b30d3e87213c7339b072702593bb6b5f4d0722e4deed43a
|
|
| MD5 |
66b7a130d57059b178b849c76c36c344
|
|
| BLAKE2b-256 |
aa5d78f8da0d1a34e8a745c5fc3dd6676e20ce57bd22e9464e99edf250bd2550
|
File details
Details for the file app_logs_ai-0.1.1-py3-none-any.whl.
File metadata
- Download URL: app_logs_ai-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8053d5f669c98e5db53bb0dd8e59a2e0115a9a5b49d13407842fd22d7f32448
|
|
| MD5 |
44846138e6db82949d1fe89c20c48032
|
|
| BLAKE2b-256 |
e8057de78ef8474cd3d67f7946aa0ac651bf2c0a5011b7ef1ad51a75d0d82019
|