I can’t get logging to work in a custom pallet when running unit tests:

RUST_LOG=runtime=debug cargo test --features rococo-local -- --nocapture

log::debug!("") doesn’t work and println!() doesn’t compile because of no-std. (edited)

The custom pallet is importing the log facade:

use frame_support::{
    dispatch::{DispatchInfo, DispatchResult, PostDispatchInfo},
    ensure, log,

Cargo.toml does not have a log crate but I tried adding log = "0.4.17" to dependencies and also dev-dependencies but that had no effect. I did not try adding it to both.

I tried RUST_LOG=debug, RUST_LOG=runtime=debug and RUST_LOG=test=debug to no avail.

IMPORTANT NOTE: The log is not in the unit tests. It’s in the custom pallet lib.rs which is being called by the unit test.

2 Answers 2


This is a Rust question.

log is just some sort of "code".

You need a trigger to activate it.




Using logging didn't work but this did:

sp_std::if_std! {
  println!("debug log");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.