Remove logheader callback feature; keep Kanta-colored extra string in default header

This commit is contained in:
Leo Vasanko
2026-08-07 00:44:06 +00:00
parent 1cd99aef01
commit 9e19a1bf21
9 changed files with 29 additions and 497 deletions
+2 -21
View File
@@ -213,30 +213,11 @@ def resolve_user_key(value: str) -> str | None:
- By default a transaction is logged with an `action by user` header followed
by the diff lines. Added paths are colored green, deleted paths red.
- `kanta.transaction(..., extra="...")` accepts a display-only string that is
appended after the action in the default header (colored by Kanta); it is
never persisted in the `ChangeRecord`.
- Register a `@kanta.logheader` callback to compose a custom header. Declare
any of `action: str`, `user: str`, `extra: str`: Kanta passes the parts
with its header colors already applied (missing `user`/`extra` as empty
strings), so callbacks only arrange text — no color codes, fallbacks, or
padding. `DictPre`/`DictPost` state dicts and the `Kanta` instance can
also be injected. The callback must be synchronous and return `str | None`.
- Multiple logheader callbacks are stacked in registration order; the first
callback to return a non-`None` result wins. If all return `None`, Kanta
falls back to the default header. The `user` part has already been through
the `logfmt` formatters.
appended after the action in the header (colored by Kanta); it is never
persisted in the `ChangeRecord`.
- The header and diff parts can be toggled independently per transaction:
`kanta.transaction(..., log={"header": True, "diff": False})`.
```python
@kanta.logheader
def format_header(action: str, user: str, extra: str) -> str:
return f"{user} {action} {extra}"
with kanta.transaction(action="update", user="alice", extra="Project X") as data:
...
```
## Migrations
- Migration source is configured on `Kanta(...)` via `migrations=`.