Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to statically disable Rust logging in production builds of my application? [duplicate]

Tags:

logging

rust

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?

like image 664
Ameo Avatar asked Nov 20 '19 21:11

Ameo


People also ask

What is a debug logger UI?

The Cast Debug Logger provides a debug overlay on the Web Receiver to show your custom log messages.

How do I turn off log on Android?

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.


1 Answers

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.

like image 87
Ameo Avatar answered Oct 01 '22 15:10

Ameo