paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.com/
1.89k stars 696 forks source link

Add a logger to unit tests #6125

Open franciscoaguirre opened 4 weeks ago

franciscoaguirre commented 4 weeks ago

Logs are very helpful for xcm debugging in particular, where we mark them all with target: xcm and get them by specifying RUST_LOG=xcm. However, this doesn't work out-of-the-box with unit tests, since we need a logger. We can use env_logger but then each test needs this line in the start: let _ = env_logger::init();. The other option is to add test-log as a dependency and import the test macro from it. This was already done in polkadot/xcm/docs/src/cookbook/relay_token_transactor/tests.rs.

We could either adopt this everywhere or create a README of how to enable logs to make people's lives easier when debugging.

bkchr commented 4 weeks ago

We have tons of tests with logging. However, I don't see the reason for this issue. If someone is debugging a test, they can just add a logger. There is no need to have a logger in every test, because not every test will always fail.

Also not sure how many people are "debugging these tests" constantly that we need an issue for this.

bkchr commented 4 weeks ago

And also don't use env_logger, we have already sp_tracing::init_for_tests().