I tried to use ansi_term to print logs because it is used in the Substrate repository for logging: https://github.com/paritytech/substrate/blob/fece0657f20e15df94be5833b164dfacd44823eb/client/informant/src/lib.rs which is mentioned also in How to Change Colors of Node Terminal Output?

use ansi_term::Colour;
 info!("♻️  Reorg on #{},{} to #{},{}, common ancestor #{},{}",
                        Colour::Red.bold().paint(format!("{}", last_num)),...);

then I found ansi_term cannot be used in my parachain precompile because my runtime must support no_std as I see #![cfg_attr(not(feature = "std"), no_std)] in the beginning of my precompile lib.rs file.

Substrate docs does not say much about color logs: https://docs.substrate.io/test/debug/

I am aware of using log::warn!() and log::error!() AND running your parachain with --execution Native can produce a tiny colorful log in yellow and red... but that is not really enough.

So how can I make colorful logs and support no_std?

  • 1
    Actually, I don't recommend you to use that for the log. Some log are pretty long, the output might be truncated if you force it to use color. Sep 16, 2022 at 4:27

1 Answer 1


You could use the color code directly.

Those crates just made a wrapper for the color code.



fn main() {
    // you could replace `println!` with `log::info!` in no_std

enter image description here


Your Answer

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

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