tracing-test icon indicating copy to clipboard operation
tracing-test copied to clipboard

feat: add feature flag to enable ansi colors and RUST_LOG filtering for terminal output

Open Frando opened this issue 11 months ago • 3 comments

While the crate description states that this crate is not intended for debugging tests but on testing the logging (which is great), we frequently still need to debug tests. We recently moved from a home-baked solution to this crate and really like the ability to assert log lines. At the same time, we quite miss the colored output and a way to set a custom filter directive when debugging tests.

This PR adds two feature flags. Without the feature flags, the behavior is fully unchanged.

  • no-log-printing: Disable log printing fully. Fixes #38
  • pretty-log-printing: Uses a different fmt layer for outputting the logs to the terminal, while keeping the layer used for assertions as it is now. The new layer for outputting allows to set a filter via RUST_LOG (while defaulting to the current filter of "trace for main crate"), and enables ansi colors unless NO_COLOR=1 is present.

The layer that is used for the assertions is kept unchanged in any case (no ansi, no way to change the filter apart from the no-env-filter feature flag).

Frando avatar Feb 05 '25 11:02 Frando

Friendly ping @dbrgn - did you have a chance to look at this?

Frando avatar Feb 20 '25 10:02 Frando

This is a great approach! I had a similar idea for log filtering in https://github.com/paritytech/polkadot-sdk/blob/master/substrate/primitives/tracing/src/lib.rs#L270

raymondkfcheung avatar Mar 14 '25 09:03 raymondkfcheung

Any news on this one? @dbrgn

b1scoito avatar Sep 27 '25 07:09 b1scoito