Final cleanup: lazy logfmt build, docstring and example fixes
- transaction.py only builds the logfmt chain when logging is enabled - callbacks.py module docstring documents the logemit special case - docs logemit example uses the settable header instead of a user lookup that would break when logfmt resolution is registered
This commit is contained in:
+3
-3
@@ -269,9 +269,9 @@ def resolve_user_key(value: str) -> str | None:
|
|||||||
def emit(ev: LogEvent):
|
def emit(ev: LogEvent):
|
||||||
if ev.kind != "change":
|
if ev.kind != "change":
|
||||||
return default_emit(ev) # delegate, no chaining needed
|
return default_emit(ev) # delegate, no chaining needed
|
||||||
actor = ev.current.get("users", {}).get(ev.user, {}).get("name", ev.user)
|
# Restyle the header; default_emit keeps routing the diff body.
|
||||||
line = Line().user(actor, width=20)(" ").action(ev.action)
|
ev.header = str(Line().user(ev.user or "-", width=20)(" ").action(ev.action))
|
||||||
ev.logger.log(ev.level, f"{line}\n" + "\n".join(ev.diff_lines))
|
return True
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Terminal Formatting Helpers
|
#### Terminal Formatting Helpers
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ default value.
|
|||||||
Log formatters are a special case: they are called per value being rendered
|
Log formatters are a special case: they are called per value being rendered
|
||||||
and receive the value plus an optional ``path`` string. They return
|
and receive the value plus an optional ``path`` string. They return
|
||||||
``str | None``; ``None`` means "fall through to the next formatter".
|
``str | None``; ``None`` means "fall through to the next formatter".
|
||||||
|
|
||||||
|
Log emitters (``logemit``) are another special case: plain callables that
|
||||||
|
receive a :class:`kanta.logging.LogEvent` and are dispatched by
|
||||||
|
:func:`kanta.logging.emit_event`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|||||||
@@ -90,8 +90,8 @@ def transaction(
|
|||||||
previous = impl.statedict
|
previous = impl.statedict
|
||||||
record = impl.queue_change(action, new_dict, user=user, mtime=mtime)
|
record = impl.queue_change(action, new_dict, user=user, mtime=mtime)
|
||||||
if record is not None:
|
if record is not None:
|
||||||
logfmt = _build_logfmt(impl, previous, new_dict)
|
|
||||||
if log is not False:
|
if log is not False:
|
||||||
|
logfmt = _build_logfmt(impl, previous, new_dict)
|
||||||
logger = (
|
logger = (
|
||||||
log if isinstance(log, logging.Logger) else transaction_logger
|
log if isinstance(log, logging.Logger) else transaction_logger
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user