Add experimental kanta CLI for inspecting databases.
This commit is contained in:
+8
-5
@@ -124,19 +124,22 @@ class LogEvent(msgspec.Struct, kw_only=True):
|
|||||||
def emit_event(
|
def emit_event(
|
||||||
ev: LogEvent,
|
ev: LogEvent,
|
||||||
handlers: Iterable[Callable[[LogEvent], Any]] = (),
|
handlers: Iterable[Callable[[LogEvent], Any]] = (),
|
||||||
|
*,
|
||||||
|
fallback: Callable[[LogEvent], None] | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Dispatch *ev* through registered logemit handlers.
|
"""Dispatch *ev* through registered logemit handlers.
|
||||||
|
|
||||||
Each handler receives the event and may log it (or not) as it sees fit.
|
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 falsy return value stops the chain: the event is considered handled.
|
||||||
A truthy return value passes the event — possibly modified — to the next
|
A truthy return value passes the event — possibly modified — to the next
|
||||||
handler. When all handlers pass, :func:`default_emit` renders the event
|
handler. When all handlers pass, the *fallback* renders the event;
|
||||||
with the built-in formatting.
|
the default fallback is :func:`default_emit` with the built-in formatting.
|
||||||
|
|
||||||
Logging must never break functionality: a crashing handler is reported
|
Logging must never break functionality: a crashing handler is reported
|
||||||
and the chain falls back to the built-in formatting, and a failure in
|
and the chain falls back to the fallback rendering, and a failure in
|
||||||
the built-in formatting itself is reported and swallowed.
|
the fallback itself is reported and swallowed.
|
||||||
"""
|
"""
|
||||||
|
render = fallback if fallback is not None else default_emit
|
||||||
try:
|
try:
|
||||||
for handler in handlers:
|
for handler in handlers:
|
||||||
try:
|
try:
|
||||||
@@ -146,7 +149,7 @@ def emit_event(
|
|||||||
break
|
break
|
||||||
if not proceed:
|
if not proceed:
|
||||||
return
|
return
|
||||||
default_emit(ev)
|
render(ev)
|
||||||
except Exception:
|
except Exception:
|
||||||
_logger.exception("failed to emit %s log event", ev.kind)
|
_logger.exception("failed to emit %s log event", ev.kind)
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ dependencies = [
|
|||||||
"msgspec>=0.20.0",
|
"msgspec>=0.20.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[project.scripts]
|
||||||
|
kanta = "kanta.__main__:main"
|
||||||
|
|
||||||
[project.optional-dependencies]
|
[project.optional-dependencies]
|
||||||
bin = [
|
bin = [
|
||||||
"blake3>=1.0.8",
|
"blake3>=1.0.8",
|
||||||
|
|||||||
Reference in New Issue
Block a user