Skip to content

AcceptanceTestSuite: suppress logs per test, only emit on failure#1218

Merged
chrjohn merged 11 commits into
masterfrom
copilot/add-logging-for-specific-test-failures
May 18, 2026
Merged

AcceptanceTestSuite: suppress logs per test, only emit on failure#1218
chrjohn merged 11 commits into
masterfrom
copilot/add-logging-for-specific-test-failures

Conversation

Copilot AI commented May 7, 2026

Copy link
Copy Markdown
Contributor

The AcceptanceTestSuite emits voluminous INFO-level logs for every test case, making CI output noisy and failures harder to diagnose.

Approach

Buffer all java.util.logging output during each individual test and replay it only when that test fails. Log suppression can be disabled via a system property for debugging purposes.

Changes

  • CapturingLogHandler (new inner static class) — a JUL Handler that accumulates LogRecords in a synchronized ArrayList; drainRecords() atomically snapshots and clears the buffer.
  • AcceptanceTest.run() — wraps each test execution with log capture:
    • Always emits a "Running test {}, filename : {}" line before suppression begins, so test progress is always visible.
    • Saves and sets all root-logger handler levels to OFF before the test runs.
    • Installs CapturingLogHandler on the root logger.
    • On failure: restores handler levels and replays the full buffered record set through them.
    • On success: silently discards the buffer.
  • -Datest.verbose=true system property — when set, bypasses the log-capturing/suppression block entirely so all logs flow normally to the existing handlers. Follows the same convention as -DskipAT and -Datest.skipslow. Default is false (suppress per-test, replay only on failure).

No new dependencies — uses only java.util.logging APIs.

// Before test: silence existing handlers, start capturing (unless -Datest.verbose=true)
if (!verboseLogging) {
    for (int i = 0; i < existingHandlers.length; i++) {
        originalLevels[i] = existingHandlers[i].getLevel();
        existingHandlers[i].setLevel(Level.OFF);
    }
    capturingHandler = new CapturingLogHandler();
    rootLogger.addHandler(capturingHandler);
}

// ... test runs ...

// In finally: restore, then conditionally replay
if (!verboseLogging) {
    for (int i = 0; i < existingHandlers.length; i++) {
        existingHandlers[i].setLevel(originalLevels[i]);
    }
    if (testFailed) {
        for (LogRecord record : capturingHandler.drainRecords()) {
            for (Handler handler : existingHandlers) {
                handler.publish(record);
            }
        }
    }
}

@chrjohn chrjohn changed the title AcceptanceTestSuite: suppress logs per test, only emit on failure AcceptanceTestSuite: suppress logs per test, only emit on failure May 7, 2026
Comment thread quickfixj-core/src/test/java/quickfix/test/acceptance/AcceptanceTestSuite.java Outdated
Copilot finished work on behalf of chrjohn May 7, 2026 14:41
Copilot AI requested a review from chrjohn May 7, 2026 14:41
@chrjohn

chrjohn commented May 12, 2026

Copy link
Copy Markdown
Member

@copilot
Cloud you please add a system property that turns the logging back on. It should be off by default. See property skipAT as reference.

Copilot AI commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

@copilot
Cloud you please add a system property that turns the logging back on. It should be off by default. See property skipAT as reference.

Done in d784f8d. Added ATEST_VERBOSE_KEY = "atest.verbose" following the same pattern as skipAT/atest.skipslow. Pass -Datest.verbose=true to bypass the capturing logic entirely and have all logs flow normally; the default (false) keeps the existing suppress-and-replay-on-failure behaviour.

Copilot AI requested a review from chrjohn May 12, 2026 07:35
@chrjohn chrjohn added this to the QFJ 3.0.2 milestone May 12, 2026
@chrjohn chrjohn marked this pull request as ready for review May 18, 2026 19:22
@chrjohn chrjohn merged commit c61418d into master May 18, 2026
29 of 30 checks passed
@chrjohn chrjohn deleted the copilot/add-logging-for-specific-test-failures branch May 18, 2026 19:26
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.

2 participants