5

While doing the tutorial of "Build the Substrate Kitties Chain" there comes a section https://docs.substrate.io/tutorials/v3/kitties/pt1/#write-the-create_kitty-dispatchable

In this there it says 'In order to use log::info, add this to your pallet's Cargo.toml file, using the matching version as Substrate upstream.'

So How to add log in cargo.toml?

2 Answers 2

5

To add log in pallets\kitties\src\cargo.toml first go into cargo.toml file and in the [dependencies] section add: log = {version = "0.4.14", feature = ["derive"]}

Just keep in mind version may change depending upon the updates. So change it accordingly. Currently on the date of writing this answer version is 0.4.14

1

Use Substrate's built-in sp-tracing! https://www.youtube.com/watch?v=ZSipV1LLUzM

add sp-tracing in the pallet cargo file under dev dependencies:

sp-tracing = { version = "6.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.37" }

use it in your code

use frame_support::{log::{info, warn}, .. };
  info!("info num: {:?}", num);
  warn!("warn num: {:?}", num);

in your pallet/mock:

pub fn new_test_ext() -> sp_io::TestExternalities {
    sp_tracing::try_init_simple();// Add this line
    system::GenesisConfig::default().build_storage::<Test>().unwrap().into()
}

Run tests with "RUST_LOG=info "

$ RUST_LOG=info cargo test -p pallet-template it_

will run tests that starts with "it_"

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.