Add kanta instance to LogEvent and make header settable
Every emitted event now carries the originating Kanta instance so logemit callbacks can reach application state attached to it. The header property gains a setter, formalizing restyle-then-delegate: assign ev.header and return truthy to keep the default diff routing with a custom header.
This commit is contained in:
+7
-5
@@ -231,16 +231,18 @@ def resolve_user_key(value: str) -> str | None:
|
||||
mechanism: when no `logemit` callback handles an event,
|
||||
`kanta.logging.default_emit` renders it with the built-in formatting.
|
||||
- A `LogEvent` carries the event `kind` (`"change"`, `"created"`,
|
||||
`"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.
|
||||
`"migrated"`, `"aborted"`), the preferred `logger` and `level`, the
|
||||
`kanta` instance, 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 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.
|
||||
plain `Created`/`Migrated` summaries. It is settable: assign
|
||||
`event.header = ...` and return truthy to restyle the header while
|
||||
keeping the default diff routing.
|
||||
- `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.
|
||||
|
||||
Reference in New Issue
Block a user