Add experimental kanta CLI for inspecting databases.

This commit is contained in:
2026-08-13 18:44:46 +00:00
parent 0b8c1d2da9
commit 8e436295aa
2 changed files with 11 additions and 5 deletions
+8 -5
View File
@@ -124,19 +124,22 @@ class LogEvent(msgspec.Struct, kw_only=True):
def emit_event(
ev: LogEvent,
handlers: Iterable[Callable[[LogEvent], Any]] = (),
*,
fallback: Callable[[LogEvent], None] | None = None,
) -> None:
"""Dispatch *ev* through registered logemit handlers.
Each handler receives the event and may log it (or not) as it sees fit.
A falsy return value stops the chain: the event is considered handled.
A truthy return value passes the event — possibly modified — to the next
handler. When all handlers pass, :func:`default_emit` renders the event
with the built-in formatting.
handler. When all handlers pass, the *fallback* renders the event;
the default fallback is :func:`default_emit` with the built-in formatting.
Logging must never break functionality: a crashing handler is reported
and the chain falls back to the built-in formatting, and a failure in
the built-in formatting itself is reported and swallowed.
and the chain falls back to the fallback rendering, and a failure in
the fallback itself is reported and swallowed.
"""
render = fallback if fallback is not None else default_emit
try:
for handler in handlers:
try:
@@ -146,7 +149,7 @@ def emit_event(
break
if not proceed:
return
default_emit(ev)
render(ev)
except Exception:
_logger.exception("failed to emit %s log event", ev.kind)
+3
View File
@@ -21,6 +21,9 @@ dependencies = [
"msgspec>=0.20.0",
]
[project.scripts]
kanta = "kanta.__main__:main"
[project.optional-dependencies]
bin = [
"blake3>=1.0.8",