Ensure Logs Are Captured for Assertions and Printed During Tests (#7769)
This PR enhances **`test_log_capture`**, ensuring logs are **captured for assertions** and **printed to the console** during test execution. ## **Motivation** - Partially addresses #6119 and #6125, to improves developer **tracing and debugging** in XCM-related tests. - Builds on #7594, improving **log visibility** while maintaining test **log capture capabilities**. - While writing tests for #7234, I noticed this function was missing. This PR adds it to streamline log handling in unit tests. ## **Changes** - Ensures logs up to `TRACE` level are **captured** (for assertions) and **printed** (for visibility). - Refines documentation to clearly specify **when to use** each function. - **Removes ANSI escape codes** from captured logs to ensure clean, readable assertions. ## **When to Use?** | Usage | Captures Logs? | Prints Logs? | Example | |----------------------------------------------|-----------------|--------------|-----------------------------------------------| | `init_log_capture(LevelFilter::INFO, false)` |Yes | No | Capture logs for assertions without printing. | | `init_log_capture(LevelFilter::TRACE, true)` | Yes | Yes | Capture logs and print them in test output. | | `sp_tracing::init_for_tests()` | No | Yes | Print logs to the console without capturing. | --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
parent
f02134c8
Pipeline
#518086
waiting for manual action
with stages
in
1 hour, 6 minutes, and 26 seconds
Stage:
Stage:
Stage:
Stage:
Stage:
Showing
- Cargo.lock 1 addition, 0 deletionsCargo.lock
- polkadot/xcm/xcm-simulator/example/src/tests.rs 1 addition, 1 deletionpolkadot/xcm/xcm-simulator/example/src/tests.rs
- prdoc/pr_7769.prdoc 10 additions, 0 deletionsprdoc/pr_7769.prdoc
- substrate/primitives/tracing/Cargo.toml 2 additions, 1 deletionsubstrate/primitives/tracing/Cargo.toml
- substrate/primitives/tracing/src/lib.rs 90 additions, 25 deletionssubstrate/primitives/tracing/src/lib.rs
prdoc/pr_7769.prdoc
0 → 100644
Please register or sign in to comment