Files
LogHive/client/README.md
T
2026-05-09 14:55:14 +08:00

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

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")