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

Uploaded Python 3

File details

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

File metadata

  • Download URL: logbench-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 b32a7825467c4f920166ef7f749023fe6db9688764ae989715ad6b5d633e72f7
MD5 c67bcec3862aca3e070321532a397961
BLAKE2b-256 dfe653ff263e5acee1b61d3b754f0e5aeabe80ee59e9e60e4fc8f19f60eb00f3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: logbench-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b3983e3d7b42f70085996671d78d60f7696de76054da4e32a1bd93af706ee4fb
MD5 f2ae19e9086cd5ff627c8f73a5152b77
BLAKE2b-256 eb249f0c10e63748e530841f0bc51ff7917783d80a9ea2a948c74a084e5aad6d

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