Skip to main content

Python SDK for Logbench

Project description

logbench-python

A Python SDK for Logbench

Install

uv add logbench
pip install logbench

Quick start

from logbench import Logbench

logger = Logbench(project_id="your-project-id")

logger.info("Server started on port 3000")
logger.warn("Disk usage above 80%")
logger.err("Failed to connect to database")

API

Logbench(project_id, **options)

Creates a new Logbench client.

Option Type Required Description
project_id str Yes Project ID from your Logbench dashboard
url str No Base URL of your Logbench instance. Defaults to "http://localhost:1447"
capture_source bool No Capture the source file and line number of each log. Defaults to True; set to False to disable.
cwd str No Project root directory. When set, strips this prefix from captured file paths, producing relative paths in the Logbench UI.

logger.info(*content)

Send an info-level log.

logger.warn(*content)

Send a warning-level log.

logger.err(*content)

Send an error-level log.

All methods accept any number of arguments of any type.

logger.info("User signed in", {"user_id": "abc123", "at": datetime.now()})
logger.err("Request failed", {"status": 500, "headers": {"x-request-id": "abc"}})

logger.info_with(options, *content)

logger.warn_with(options, *content)

logger.err_with(options, *content)

Same as info, warn, and err, but with an additional LogOptions first argument for attaching metadata:

Option Type Description
bookmark bool Mark this log as bookmarked in the UI
annotation str Free-text annotation to attach to the entry
logger.info_with(
    {"bookmark": True, "annotation": "deploy v2.1.0"},
    "Deployment started",
    {"version": "2.1.0"},
)

LogLevel

Exported enum for the three log levels if you need to reference them directly.

from logbench import LogLevel

LogLevel.Info  # "INFO"
LogLevel.Warn  # "WARNING"
LogLevel.Err   # "ERROR"

Resource management

The client holds an HTTP connection pool. Use it as a context manager or call close() when done:

with Logbench(project_id="your-project-id") as logger:
    logger.info("hello")

# or manually
logger = Logbench(project_id="your-project-id")
logger.info("hello")
logger.close()

How it works

Each log call sends a POST request to your Logbench instance:

POST {url}/api/projects/{project_id}/logs/ingest

Errors from the HTTP call are silently caught so logging never crashes your application.

Project structure

src/logbench/
  __init__.py   Exports
  types.py      Type definitions
  enums.py      LogLevel enum
  utils.py      Internal helpers (source location capture, JSON encoding)
  client.py     Logbench client class

License

MIT

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

logbench-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

logbench-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file logbench-0.1.0.tar.gz.

File metadata

  • Download URL: logbench-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for logbench-0.1.0.tar.gz
Algorithm Hash digest
SHA256 da3b244776f72faba4097a0ad2540b786fe18d8d7f5f669c8a0222b8b5d50646
MD5 bfea64bd9f87ef31790dd4517a62a1bf
BLAKE2b-256 269e84d1758923ee71018bab2d8e2c75e58da3f41805995fa0aa84e5c518b565

See more details on using hashes here.

File details

Details for the file logbench-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: logbench-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for logbench-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2a174e20c31c5e9a87f7191540c592ca408852eeba388d7099901e7b78e143b
MD5 67ec13681545fcd092a8952ff28b0fba
BLAKE2b-256 1a70c9c6b7e2f2661510fc8ead624e707d98f940c7c408384e3b357356542fc2

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