I have a WebAssembly module written in Rust that performs logging for debug purposes via the log
crate during development. I notice that, even when I don't configure a logger, the formatting and calls to internal log
functions remain in the generated WebAssembly module. This wastes bytes since the output of those functions will never be used/displayed.
Is there any way to statically disable logging without having to remove the log macro calls in the code? Additionally, is there a way to only disable this in release builds?
The Cast Debug Logger provides a debug overlay on the Web Receiver to show your custom log messages.
Turn off logging and debugging You can deactivate logging by removing calls to Log methods in your source files. You can disable debugging by removing the android:debuggable attribute from the <application> tag in your manifest file, or by setting the android:debuggable attribute to false in your manifest file.
Yes; the log
crate provides features flags that allow logging to be statically disabled at compile time up to a certain level.
If you want to completely disable all logging in release builds but keep normal logging in debug builds, change your entry in Cargo.toml
to include the release_max_level_off
feature like this:
log = { version = "0.4", features = ["release_max_level_off"] }
This will cause all calls to logging functions to be eliminated from the resulting binary, taking any related formatting code with it via dead code elimination.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With