abfd07331e
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1.8 KiB
1.8 KiB
LogHive Client SDK
Python client SDK for sending logs to LogHive.
Installation
pip install loghive-client
Or install from source:
cd client
pip install .
Quick Start
Sync mode (recommended for scripts, Django, Flask)
from loghive_client import LogHiveLogger
logger = LogHiveLogger(
project="my-awesome-app",
api_key="your-api-key",
endpoint="http://localhost:8000",
)
logger.info("Server started", extra={"port": 8080})
logger.error("Database timeout", exc_info=True)
Async mode (for FastAPI, aiohttp, asyncio)
from loghive_client import AsyncLogHiveLogger
import asyncio
async def main():
async with AsyncLogHiveLogger(
project="my-api",
api_key="your-api-key",
endpoint="http://localhost:8000",
) as logger:
await logger.info("API started")
# ...
asyncio.run(main())
Standard logging integration (zero code change)
Add the handler to your existing logger:
import logging
from loghive_client import LogHiveHandler
handler = LogHiveHandler("my-project", "api-key", "http://localhost:8000")
logging.getLogger().addHandler(handler)
# All existing logger calls now forward to LogHive
logging.info("This goes to LogHive too!")
Configuration
| Param | Default | Description |
|---|---|---|
project |
(required) | Your project name in LogHive |
api_key |
(required) | Your project's API key |
endpoint |
http://localhost:8000 |
LogHive server URL |
batch_size |
50 | Max entries per HTTP request |
flush_interval |
2.0 | Seconds between flushes |
max_retries |
3 | Retries on failure |
timeout |
5.0 | HTTP request timeout |
Trace ID (request correlation)
logger.set_trace_id("req-abc-123")