For me what works best is to put the flag in build.rs, I usually add some logic like: let profile = std::env::var("PROFILE").unwrap(); let log_level = match profile.as_str() { "release" => "info", _ => "debug", }; println!("cargo:rustc-env=DEFMT_LOG={}", log_level);