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.8.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.8-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: logforge_py-0.1.8.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.8.tar.gz
Algorithm Hash digest
SHA256 db56c18371afb63fcc4fa8d4768f059493e48f393fe6820fce74fd67a30343eb
MD5 ba2d81681523b054861b3ba98e65dbff
BLAKE2b-256 b1a356b0acd898ac565f8d7a4b22a030ad53e976039efe2159c97255a99eb00e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: logforge_py-0.1.8-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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 05bd16f6fea76e3a3a113ffd40a0032c0b7e38b7510332a12a6c3f5d438e3053
MD5 8d3d28926949dad1c0b06574a14d3914
BLAKE2b-256 73d60389967229637e7fe553f3066aad188ff5707d03356fdbde27d4aab08002

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