Skip to main content

Official Python SDK for LogForge — self-hosted log management and monitoring

Project description

logforge-py

Official Python SDK for LogForge, self-hosted log management and monitoring.

Compatible with Python 3.8+. Logs are batched and sent in a background thread.

Installation

# With requests (recommended)
pip install logforge-py[requests]

# With httpx
pip install logforge-py[httpx]

# With both
pip install logforge-py[all]

Quick Start

from logforge import LogForge

logger = LogForge(
    api_key="YOUR_API_KEY",           # from LogForge dashboard → Project Settings
    endpoint="https://logs.myapp.com", # your LogForge backend URL
    environment="production",
    channel="default",
)

logger.info("App started")
logger.warning("Cache miss rate high", metadata={"rate": 0.42})
logger.error("DB write failed", metadata={"table": "orders"}, tags=["database"])

# Capture exceptions with full traceback
try:
    1 / 0
except ZeroDivisionError as e:
    logger.capture_exception(e, channel="math")

# Flush remaining logs and stop the background thread before exit
logger.shutdown()

Auto-register shutdown

import atexit
atexit.register(logger.shutdown)

Constructor Options

Option Type Default Description
api_key str required Project API key
endpoint str required LogForge backend base URL
environment str 'production' Environment tag
channel str 'default' Default log channel
batch_size int 10 Max logs per flush batch
flush_interval float 5.0 Seconds between auto-flushes
retry_attempts int 3 Retry attempts on failure
timeout float 10.0 HTTP request timeout (seconds)
debug bool False Log SDK errors via Python logging

API

Logging

logger.info(message, **options)
logger.warning(message, **options)   # alias: warn()
logger.error(message, **options)
logger.debug(message, **options)
logger.critical(message, **options)
logger.capture_exception(exc, **options)

Every method accepts keyword options:

logger.error(
    "Payment failed",
    channel="payments",
    environment="staging",
    metadata={"order_id": "ORD-456"},
    tags=["payments", "critical-path"],
)

User Context

logger.set_user("user_123", "john@example.com", name="John Doe")
logger.clear_user()

Channel / Environment

logger.set_channel("auth")
logger.set_environment("staging")

Flush / Shutdown

logger.flush()     # block until current queue is sent
logger.shutdown()  # flush + stop background thread

Django Integration Example

# settings.py (or apps.py AppConfig.ready())
from logforge import LogForge
import atexit

log = LogForge(api_key="YOUR_KEY", endpoint="https://logs.myapp.com")
atexit.register(log.shutdown)

# In views.py
import traceback

def my_view(request):
    try:
        do_something()
    except Exception as exc:
        log.capture_exception(exc, metadata={"path": request.path})
        raise

FastAPI / async usage

The SDK is synchronous and thread-safe. It works fine alongside async frameworks — the background flush thread runs independently.

from contextlib import asynccontextmanager
from fastapi import FastAPI
from logforge import LogForge

logger = LogForge(api_key="KEY", endpoint="https://logs.myapp.com")

@asynccontextmanager
async def lifespan(app: FastAPI):
    yield
    logger.shutdown()

app = FastAPI(lifespan=lifespan)

License

MIT — see LICENCE

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

logforge_py-0.1.9.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logforge_py-0.1.9-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file logforge_py-0.1.9.tar.gz.

File metadata

  • Download URL: logforge_py-0.1.9.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for logforge_py-0.1.9.tar.gz
Algorithm Hash digest
SHA256 18cdb007c414e6fe012232372b0c80d6c9bbdd2ef2e521a3b4dca635026ccdcf
MD5 643620919034c0c0e3910f10ad4ca498
BLAKE2b-256 8a22610e3143d71586288bfce21d6900b32c26d6de8e1f536da9093218e6fef2

See more details on using hashes here.

File details

Details for the file logforge_py-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: logforge_py-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for logforge_py-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 b20563adb94a5b63155bb02e56f8d3730006953cc73478e74581fd35248d3ef0
MD5 8b435c50de199c847af5484f23cd2281
BLAKE2b-256 a553b659fa0d9689fd49234be222096d7e1cf5890337a127c2b5c54b3874128b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page