Unify default emitter around universal LogEvent.header

All event kinds now share one shape: a one-line header plus an optional
diff body for changes. LogEvent.header is a lazy property covering every
kind (change, aborted, created, migrated), and default_emit reduces to
logging the header plus routing diff_lines to the .diff child logger.
Custom emitters can tap the same blocks - header, diff_lines, Line,
format_diff - instead of reimplementing formatting per message type.
This commit is contained in:
Leo Vasanko
2026-08-07 05:52:26 +00:00
parent cc319ce065
commit c90db530fd
4 changed files with 71 additions and 38 deletions
+10 -4
View File
@@ -234,10 +234,16 @@ def resolve_user_key(value: str) -> str | None:
`"migrated"`, `"aborted"`), the preferred `logger` and `level`, and all
relevant state: `action`, `user`, `extra`, `error` (for aborted
transactions), `diff`, `previous`/`current` state dicts, the built `logfmt`
chain, and version info for migration events. The default `"aborted"`
rendering is `<action>[ by <user>] transaction aborted: <error>` with the
action and user colored and the user resolved via `logfmt`. Pretty
`header` and `diff_lines` are lazy properties, built only if accessed.
chain, and version info for migration events.
- The built-in formatting is assembled from standard blocks that custom
emitters can reuse as-is or replace piecemeal:
- `event.header` — a lazy property producing the default one-line header
for any kind: `<action>[ <extra>][ by <user>]` for changes,
`<action>[ by <user>] transaction aborted: <error>` for aborts, and the
plain `Created`/`Migrated` summaries.
- `event.diff_lines` — a lazy property producing the pretty diff body for
change events (built only if accessed).
- `default_emit` itself is just `header` plus the `diff_lines` routing.
- `@kanta.logemit` registers a callback receiving the event. The callback
decides what is logged and where: it may log one or more messages on
`event.logger`, log somewhere else, or nothing at all. A falsy return