DEV Community

nikania
nikania

Posted on

Using log in Substrate

How to log in substrate pallets and how to see logs when running node (can be useful to see existing logs in polkadot when debugging).

Import log crate in Cargo.toml of pallets/template

[dependencies]
log = "0.4"
Enter fullscreen mode Exit fullscreen mode

Add some logging to extrinsic do_something in pallet-template (gibberish in my case)

log::trace!(target: "lalala", "do_something is working!");
log::trace!(target: "ononono", "do_something is working!");
log::trace!(target: "test::werr", "do_something is working!");
...
log::trace!(target: "lalala", "do_something is done!");
log::trace!(target: "ononono", "do_something is done!");
log::trace!(target: "test::werr", "do_something is done!");
Enter fullscreen mode Exit fullscreen mode

Build node, and run with log filtering (filters only target: "lalala" trace logs):

./target/release/node-template --dev --tmp --log lalala=trace
Enter fullscreen mode Exit fullscreen mode

when execute extrinsics, trace log is in output:

Image description

different filtering (notice that target: "test::werr" can be filtered like that test=trace)

./target/release/node-template --dev --tmp --log lalala=trace ononono=trace test=trace
Enter fullscreen mode Exit fullscreen mode

--different output

Image description

For example to trace xcm messages in parachains/relay chain filter can be used: --log xcm=trace

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay