5

What is the best practice for logging in pallets? Is there any overhead leaving them in at a debug/trace level? Or should we never use them outside of development?

e.g.

log::debug!("")

2 Answers 2

2

Generally, it is recommended to avoid logging inside the runtime This can lead to some issues, a few I can think of are:

  • Increases the size of the Wasm binary that your chain will be running.
  • Ideally, you want to keep your extrinsics as concise as possible. Adding extra execution steps may result in an increase in weight, which could lead to higher fees for executing the call.
  • Depending on the wasm compiler used to create the binary, logging outside of a Debug environment can cause some problems. This is because WebAssembly might not have access to some system-level calls needed to print data.

Refer to the Debug Section - Substrate docs for more info.

In a production environment, it is recommended to use Errors and Events to provide information on the internal behavior of the call within a pallet.

Here’s an answer to a different question that could also help.

0

You abosultely can log in runtime.

No need to worry about the WASM. Just use it like you are developing a Rust program.

You can enable this feature while building the runtime release. It will disable the log in the WASM.

You can still see the log by not enable this feature in the binary build.

https://github.com/paritytech/polkadot/blob/fbb74beced0f1deb84ab2f7c808d84cc7b413e53/runtime/polkadot/Cargo.toml#L289-L294

2
  • When logs are not enabled (for mainnet/production), is there zero overhead or does it leave some code in? Apr 20, 2023 at 13:16
  • No any log code gets injected.
    – AurevoirXavier
    Apr 20, 2023 at 13:42

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.