Skip to content

feat(py): add min_level to set_log_hook - #401

Draft
aka-bo wants to merge 1 commit into
kms-decrypt-error-visibility-v2from
python-log-hook-min-level
Draft

aka-bo wants to merge 1 commit into
kms-decrypt-error-visibility-v2from
python-log-hook-min-level

Conversation

@aka-bo

@aka-bo aka-bo commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Problem

set_log_hook installed its sink at warn with no way to change it, so debug and info records from the Rust core (key loads and creations, metastore calls, per-region KMS failure detail) could not be observed from Python. The Python docs also described a set_log_hook_sync(..., min_level=...), which asherah-py does not provide.

Change

  • set_log_hook(callback, min_level=None) accepts "error", "warn" (or "warning"), "info", "debug" and "trace", case-insensitively. The default is warn.
  • An unknown string raises ValueError and a non-string raises TypeError, in both cases before the installed hook is touched.
  • The level is applied to both the async dispatcher, which drives log::max_level, and the inner sink.
  • The type stub, README and the getting-started, aws-production-setup, testing and troubleshooting guides now describe the real API. The examples that expected debug events from a default hook install it at min_level="debug", and getting-started no longer mentions synchronous hook variants.

Behavior changes

None for existing callers. callback remains required, as on main; passing None still clears the hook; the default level is still warn.

Scope

Python binding only. Stacked on the KMS error-message PR (#400).

Out of scope: a min_level option for the Node and Java log hooks, which are also fixed at warn.

Tests

In asherah-py/tests/test_hooks.py:

  • test_log_hook_min_level_debug_delivers_debug_records: the default hook receives only warn and error records during an encrypt; with min_level="debug" debug records arrive and trace records do not.
  • test_log_hook_invalid_min_level_raises_value_error: unknown names (empty, "verbose", "critical") raise ValueError listing the accepted values, a non-string raises TypeError, and "WARNING" is accepted.
  • test_log_hook_callback_is_required_and_rejected_calls_keep_the_hook: set_log_hook() raises TypeError, and calls rejected for a missing callback or a bad level leave the installed debug hook receiving events.

A Rust unit test covers the level-name parsing, including case, warning and rejected names such as off.

🤖 Generated with Claude Code

@aka-bo
aka-bo added this pull request to stack #402 October 27, 2026 21:12
set_log_hook always installed its sink at Warn, so debug and info
records from the Rust core (key loads and creations, metastore calls)
could not be observed from Python, and the docs described a
set_log_hook_sync(..., min_level=...) that asherah-py does not provide.

set_log_hook(callback, min_level=None) now accepts "error", "warn" (or
"warning"), "info", "debug" or "trace", case-insensitively; omitting
min_level or passing None keeps the Warn default. Any other string
raises ValueError and a non-string raises TypeError, in both cases
before the installed hook is touched. The level is applied to the async
dispatcher, which drives log::max_level, and to the inner sink. The
callback argument stays required, so set_log_hook() and
set_log_hook(min_level="debug") raise TypeError instead of removing an
installed hook.

The type stub, README, getting-started and troubleshooting docs now
describe the real API, and getting-started no longer mentions
synchronous hook variants. The testing and AWS production setup
examples that expected debug events (key loads, IK creation) from a
default hook now install it at min_level="debug".

Co-Authored-By: Claude <noreply@anthropic.com>
@aka-bo
aka-bo force-pushed the python-log-hook-min-level branch from a626183 to ed9028d Compare October 27, 2026 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant