Conversation
Pact FFI 0.5.5 lets a host correlate plugin activity with a test and
receive plugin log entries. `pact.plugins` exposes this in the main
library:
- `set_test_run_id` tags plugin requests from the current thread.
- `register_log_callback` delivers each entry as a `PluginLogEntry`.
- `forward_to_logging` emits entries through the standard `logging`
module, with the instance ID, test run ID and plugin target attached
to each record.
- `get_logs` returns the entries buffered for a plugin instance, with
the timestamp converted to a UTC `datetime`.
A single CFFI trampoline is registered with the library and dispatches
to whichever Python callable is current. The library ignores a NULL
registration, so this is what makes `register_log_callback(None)` stop
delivery.
The FFI only installs its plugin log sink from `pactffi_init` and
`pactffi_init_with_log_level`, so the module and the logging docs
direct users to `pact_ffi.init_with_log_level` in place of
`log_to_stderr`.
Signed-off-by: JP-Ellis <josh@jpellis.me>
Assisted-by: Claude Code:claude-opus-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Pact FFI 0.5.5 added plugin observability: a per-thread test run ID sent to plugins, a log callback for entries from any running plugin, and a per-instance log buffer. The
pact-python-ffi0.5.8 release wrapped these; this PR surfaces them in the main library aspact.plugins.What it adds
set_test_run_id— tags plugin requests from the current thread so log entries can be attributed to a test.register_log_callback— delivers each entry as aPluginLogEntrydataclass.forward_to_logging— ready-made callback emitting through the standardloggingmodule at the equivalent level, withplugin_instance_id,test_run_idandplugin_targetattached to each record.get_logs— the entries buffered for a plugin instance, withtimestamp_msconverted to a UTCdatetime.A single CFFI trampoline is registered with the library and dispatches to whichever Python callable is current. Upstream ignores a
NULLregistration, so this is what makesregister_log_callback(None)actually stop delivery.Prerequisite worth knowing
The FFI only installs its plugin log sink from
pactffi_init/pactffi_init_with_log_level, not fromlog_to_stderr. Without one of those, the callback is silently never invoked. The module docstring anddocs/logging.mddirect users topact_ffi.init_with_log_levelin its place; ideally upstream would install the sink frompactffi_register_plugin_log_callbackitself.Verification
Nonenormalisation, callback replacement and deregistration, andloggingforwarding.PACT_PLUGIN_DIRthat writes to stderr was used. Entries arrived throughforward_to_loggingwith the extras populated, andget_logsreturned the same entries withplugin_name,source="Stderr"and timestamps.mkdocs buildresolves every cross-reference in the new module and the logging page.