Skip to content
src.fastware.error_log
Edit
On this page

SQLite-backed, thread-safe append-only error log that records 5xx responses with request context and exposes a recent() query.

#src.fastware.error_log

#src.fastware.error_log

SQLite-backed error log for recording and querying 5xx server responses with request context, tracebacks, and timestamps for post-mortem analysis.

Provides a simple append-only store that the request timing middleware can write to on server errors. Each entry captures enough context for dashboard display and post-mortem investigation.

Usage::

from fastware.error_log import ErrorLog

error_log = ErrorLog("errors.db") error_log.append( method="POST", path="/api/deploy", status_code=500, detail="Docker timeout", request_id="abc-123", )

#ErrorLog

Append-only SQLite error log with non-blocking writes.

append() never touches SQLite on the calling thread. Instead it enqueues the entry and a single dedicated background worker thread performs the connect/INSERT/commit off the event loop. This keeps the ASGI event loop responsive even during 5xx bursts, when the request timing middleware calls append() on every failing request.

Ordering and durability:

  • A single FIFO queue and a single writer thread preserve insertion

order. The timestamp is captured at append() time so it reflects the true event order regardless of write latency.

  • recent() (and the explicit flush()) drain the queue before

reading, so reads always observe every preceding append().

  • Errors raised by the writer (e.g. a bad path) are surfaced -- not

swallowed -- the next time flush()/recent() is called.

Args:

  • path: Filesystem path for the SQLite database. Created on

first write if it does not exist.

#_run_worker

python
def _run_worker(self) -> None

Drain the queue, writing each entry with one long-lived connection.

#append

python
def append(self, *, method: str, path: str, status_code: int, detail: str='', request_id: str='', user: str='', traceback: str='') -> None

Enqueue an error entry for non-blocking, off-thread persistence.

Returns immediately; the actual SQLite write happens on the background worker thread. The timestamp is captured here so ordering reflects the true event order regardless of write latency.

#flush

python
def flush(self) -> None

Block until all queued writes have been committed.

Raises any error the background writer encountered while persisting entries, so failures are surfaced rather than silently dropped.

#recent

python
def recent(self, limit: int=50) -> list[dict]

Return the most recent limit error entries, newest first.

Pending queued writes are flushed first, so the result reflects every preceding append().

#close

python
def close(self) -> None

Gracefully stop the background writer after draining pending writes.

More tools from this site

  • claudestream Drive Claude Code from Python: run it as a subprocess and read its output as typed events, with async and sync sessions, sandbox policies, and tools you define in Python
  • claudewheel A TUI Claude Code Launcher that lets you have more than one profile, manage sessions lifecycle, pick the exact CC version, model to use (even older unlisted ones), pick which GitHub account to use, etc.
  • dirstat Fast, single-binary directory statistics CLI: every file under a tree grouped by format, with counts, sizes, and lines of code, as a colored terminal table or as JSON
  • go-toml-edit Zero-dep TOML editing library for Go with comment preservation
  • howmuchleft The fastest Claude Code statusline: context window, 5-hour, and weekly limit usage as three customizable gradient bars, rendering in about 6 ms
  • orxtra
  • pgdesign
  • predraw Declarative rendering pipeline: describe a scene in JSON and get SVG, PNG and WebP out, with light and dark style tokens, reusable components and text converted to path outlines
  • reposummary Turn a git repository's history into a Markdown journal: pick a time window or revision range and get a readable digest of what changed, optionally narrated by an LLM
  • rlsbl Release orchestration and project scaffolding CLI that bumps versions, validates a structured JSONL changelog, tags only the commit CI verified, and publishes to npm, PyPI, Go and more
  • safegit git wrapper CLI that gives each commit its own temporary index and retries ref updates on conflict, so concurrent agents share one repository
  • saferm Command-line replacement for rm that archives every deletion with a mandatory reason and the context it ran in, so deleted files can be listed, inspected and restored
  • selfdoc Static Site Generator that builds a project's documentation site directly from its source code, so the docs can never drift from the code they describe, with SEO/AEO, first-class blog, search, and cross-project linking built in
  • strictcli
  • stricttest An always-on test-isolation floor: a pytest plugin and a Go env-hygiene module that make a test suite structurally unable to reach real credentials, the real HOME, the network, or the development repository.
  • wesktop A Python framework that turns an ASGI web app into a desktop application, serving it from a local Granian server and displaying it in a native OS window via pywebview
Search