node.jsrustwasi

Calling console.log from rust wasm32-wasi without the need for ssvm/ssvmup


I would like to debug using messages to the console.log.

We have a rust wasm32-wasi function being called from javascript running in nodejs. We can not use ssvm/ssvmup due to other restrictions.

Is there anything we can do to see messages from our wasm code in the console?


Solution

  • This is answered in The wasm-bindgen Guide: Using console.log:

    Another potential alternative, if you're doing a lot of logging you may want to consider using the log crate with the wasm-logger facade:

    wasm_logger::init(wasm_logger::Config::default());
    
    // Logging
    log::info!("Some info");
    log::error!("Error message");