ink icon indicating copy to clipboard operation
ink copied to clipboard

How to log inside runtime chain extension impl?

Open frankli-dev opened this issue 4 years ago • 5 comments

impl ChainExtension<Runtime> for CustomChainExtension {
        fn call<E: Ext>(
            func_id: u32,
            env: Environment<E, InitState>,
        ) -> Result<RetVal, DispatchError>
            where
                <E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,
                <E as Ext>::T: orml_tokens::Config,
        {
            match func_id {
                0 => {
                    // deposit
                    let mut env = env.buf_in_buf_out();
                    let input_data = env.read(56)?;

                    log::debug!("hello ~~ deposit ~~");

I try to log hello ~~ but it doesn't show up in the console. What should I config to log inside chain extension runtime?

I also tried RUST_LOG=debug RUST_BACKTRACE=1 ./target/release/polkadex-node --dev --tmp -lruntime=debug but it doesn't work

frankli-dev avatar Nov 09 '21 16:11 frankli-dev

@cmichi Could you take a quick look here, please? Thanks

frankli-dev avatar Nov 10 '21 04:11 frankli-dev

@frankli-dev You can use e.g.

info!(
    target: "runtime",
    "[ChainExtension]|call|func_id:{:}", func_id
);

inside your runtime. If you then run the node via substrate-contracts-node --tmp --dev it will show up on the console.

I think in your code above the issue is that you use -lruntime=debug, but don't use log::debug!(target: "runtime", …);.

cmichi avatar Nov 10 '21 07:11 cmichi

@cmichi it doesn't still work for me. I'm running on my own node which has custom chain extension implementation on the runtime

frankli-dev avatar Nov 10 '21 12:11 frankli-dev

@frankli-dev Have you tried starting without the -l? Maybe try panic-king in your custom chain extension in the runtime, just to verify that the function is even hit?

cmichi avatar Nov 10 '21 13:11 cmichi

@frankli-dev Have you tried starting without the -l? Maybe try panic-king in your custom chain extension in the runtime, just to verify that the function is even hit?

yes. I tried to panic in the entry and it panics there. So the function is called. you mean runtime=debug?

frankli-dev avatar Nov 10 '21 13:11 frankli-dev