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

Uploaded Python 3

File details

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

File metadata

  • Download URL: logforge_py-0.2.0.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.2.0.tar.gz
Algorithm Hash digest
SHA256 6b013f05150f33873561aabbf89fcfd2f631b1cb1475dd507181a829b0ab8305
MD5 7bb384142990c8558551c8d7eec412b8
BLAKE2b-256 5644bfd986e3e051c1c116f936bf4a7a2e0eb70c7af76955b092ad7b7afab862

See more details on using hashes here.

File details

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

File metadata

  • Download URL: logforge_py-0.2.0-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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 238f09fb42d9f49384fde97629a232a75511af38a632bd964c80f159f90ea3f2
MD5 bd3561d19cb04fbd2c98e96b9b3f7a17
BLAKE2b-256 3e401d345a2a75a426a803b7eb19b719a464216ae37f05468a98d71cb33f5f78

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