In wasm32-unknown-unknown target, is it possible to have println!(...) route to the dev console, so we don't have to use
web_sys::console::log_1(&msg.into())
everywhere ?
In wasm32-unknown-unknown target, is it possible to have println!(...) route to the dev console, so we don't have to use
web_sys::console::log_1(&msg.into())
everywhere ?
You can define a macro with macro_rules! that will do that. But instead of shadowing println you might want to call it log or something similiar to avoid confusion.
not generically useful but worked:
https://github.com/Respo/respo.rs/blob/main/src/respo/util.rs#L84-L89
The problem with both of these solutions is that it requires I add web_sys feature console as a dependency to everywhere I want to use println.
Logically this seems a bit weird -- I have some crates that are largely data structures (but occasionally printf debugging) and now they depend on web_sys feature console.
I am wondering if there is another way (in the spirit of set panic hook), where those libraries do NOT depend on web_sys, but the 'main web_sys crate, at runtime, hijacks println and reroutes it to console log'.
not much ideas. got some search results but looks more complicated to use:
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.