Skip to content

Document how to configure FFI logging#1303

Merged
JP-Ellis merged 3 commits intomainfrom
copilot/document-ffi-logging-configuration
Oct 22, 2025
Merged

Document how to configure FFI logging#1303
JP-Ellis merged 3 commits intomainfrom
copilot/document-ffi-logging-configuration

Conversation

Copy link
Contributor

Copilot AI commented Oct 22, 2025

Summary

This PR adds comprehensive documentation on how to configure FFI (Foreign Function Interface) logging in Pact Python. While the Python code uses the standard library logging module, the underlying Rust FFI cannot interface with it directly, requiring separate configuration.

Changes

New Documentation Page

Created docs/logging.md covering:

  • Basic Configuration: How to use pact_ffi.log_to_stderr() to direct FFI logs to standard error
  • Log Levels: Documentation of all available levels (OFF, ERROR, WARN, INFO, DEBUG, TRACE)
  • Recommended Setup: Session-scoped pytest fixture example for conftest.py
  • One-time Initialization: Clear warning that FFI logging can only be configured once per process
  • Advanced Configuration: Coverage of log_to_buffer() for capturing logs to internal memory, with notes about features planned but not yet implemented
  • Troubleshooting: Common issues and solutions
  • API References: Links to complete API documentation

Updates to Existing Documentation

Added brief logging sections to both docs/consumer.md and docs/provider.md:

  • Consumer Documentation: Added logging section after "Multi-Interaction Testing" explaining how to enable FFI logging for debugging mock service issues, with pytest fixture example and link to full documentation
  • Provider Documentation: Added logging section after "Verifying from a Pact Broker" explaining how to enable FFI logging for debugging provider verification and state handlers, with pytest fixture example and link to full documentation

Example

The recommended setup for pytest users:

import pytest
import pact_ffi

@pytest.fixture(autouse=True, scope="session")
def pact_logging():
    """Configure Pact FFI logging for the test session."""
    pact_ffi.log_to_stderr("INFO")

Navigation Update

Updated docs/SUMMARY.md to include the new Logging page in the documentation menu.

Motivation

Users often struggle to understand why Pact FFI logs don't appear when using Python's standard logging configuration. This documentation addresses that confusion by:

  1. Explaining the architectural reason (FFI can't interface with Python logging)
  2. Providing clear, working examples
  3. Warning about the one-time initialization constraint
  4. Offering troubleshooting guidance
  5. Making logging configuration discoverable from both consumer and provider documentation pages

Fixes #1302

Original prompt

This section details on the original issue you should resolve

<issue_title>Document how to configure FFI logging</issue_title>
<issue_description>### Have you read the Contributing Guidelines on issues?

Description

Improve the documentation as to how logging can be configured for the FFI. Specifically, it should:

  1. Direct users to the pact_ffi.log_to_stderr function

  2. Advise that the FFI logging can only be initialised once, and as such, is probably best placed in a fixture within conftest.py:

    import pytest
    import pact_ffi
    
    @pytest.fixture(autouse=True, scope="session")
    def pact_logging():
        pact_ffi.log_to_stderr("INFO")
  3. Advise that more advanced configuration can be set up (such as logging to an internal buffer and retrieving logs on demand).

Motivation

While the Python code uses the standard library logging, the underlying FFI cannot interface with that. This is why there's a need to configure logging first.

Have you tried building it?

No response

Self-service

  • I'd be willing to contribute this feature to Pact Python myself.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #1302


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Document how to configure FFI logging Document how to configure FFI logging Oct 22, 2025
Copilot AI requested a review from JP-Ellis October 22, 2025 21:36
@JP-Ellis
Copy link
Contributor

@copilot Please also update the existing provider and consumer docs to include a brief description of how to enable logging, and link to the new docs/logging.md document too.

Copy link
Contributor Author

Copilot AI commented Oct 22, 2025

@copilot Please also update the existing provider and consumer docs to include a brief description of how to enable logging, and link to the new docs/logging.md document too.

Added logging sections to both consumer.md and provider.md with links to the detailed logging documentation. Each section includes a brief explanation and the recommended pytest fixture setup. See commit d0ebef5.

@codecov
Copy link

codecov bot commented Oct 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52%. Comparing base (b531a5f) to head (68f58ed).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@         Coverage Diff          @@
##           main   #1303   +/-   ##
====================================
  Coverage    52%     52%           
====================================
  Files        32      32           
  Lines      3744    3744           
====================================
  Hits       1967    1967           
  Misses     1777    1777           
Flag Coverage Δ
tests 52% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JP-Ellis JP-Ellis force-pushed the copilot/document-ffi-logging-configuration branch from d0ebef5 to 68f58ed Compare October 22, 2025 21:56
@JP-Ellis JP-Ellis marked this pull request as ready for review October 22, 2025 21:56
Copilot AI review requested due to automatic review settings October 22, 2025 21:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive documentation for configuring FFI logging in Pact Python, addressing the architectural constraint that the Rust FFI cannot directly interface with Python's standard logging module.

Key changes:

  • Created a dedicated logging documentation page with complete configuration guidance
  • Added logging sections to consumer and provider documentation for discoverability
  • Updated navigation to include the new logging page

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
docs/logging.md New comprehensive logging documentation covering basic and advanced configuration, troubleshooting, and API references
docs/consumer.md Added logging section with pytest fixture example for debugging mock service issues
docs/provider.md Added logging section with pytest fixture example for debugging provider verification
docs/SUMMARY.md Added logging page to documentation navigation menu

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@JP-Ellis JP-Ellis enabled auto-merge (squash) October 22, 2025 21:57
@JP-Ellis JP-Ellis merged commit d3a1ef1 into main Oct 22, 2025
59 checks passed
@JP-Ellis JP-Ellis deleted the copilot/document-ffi-logging-configuration branch October 22, 2025 22:01
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.

Document how to configure FFI logging

3 participants