title: Removing debug macros in Rust
body: <p>I'm writing an application that uses slog for logging multiple things during its execution. As such, I make extensive use of the <code>info!</code>, <code>error!</code>, <code>warn!</code> and <code>debug!</code> macros.</p>
  
  <p>However, as expected, the <code>debug!</code> calls are there to help me debug the applications and I don't want those calls polluting the logs when actually using the application.</p>
  
  <p>I've been trying to compile them away without success. This is the line I'm using: <code>RUSTFLAGS="$RUSTFLAGS -C debug-assertions" cargo build --release</code></p>
  
  <p>The compilation goes on smoothly, but on execution I see all the debug calls.</p>
  
  <p>The following is a working example of my issue:</p>
  
  <p>Cargo.toml:</p>
  
  <pre><code>[dependencies]
  slog = { version = "1.5", features = ["max_level_trace", "release_max_level_warn"] }
  slog-stream = "1.2.0"
  slog-term = "1.5.0"
  slog-json = "1.2.1"
  slog-stdlog = "1.1.0"
  log = "0.3.7"
  </code></pre>
  
  <p>main.rs:</p>
  
  <pre><code>#[macro_use]
  extern crate slog;
  extern crate slog_stream;
  extern crate slog_term;
  extern crate slog_json;
  extern crate slog_stdlog;
  #[macro_use]
  extern crate log;
  
  use std::path::Path;
  use std::fs::OpenOptions;
  use slog::DrainExt;
  
  fn init_logger(work_dir : &amp;Path) {
      let mut log_dir_buf = work_dir.to_path_buf();
      log_dir_buf.push("log");
  
      if !log_dir_buf.exists() {
          std::fs::create_dir(log_dir_buf.as_path()).unwrap();
      }
  
      log_dir_buf.push("the_log_file.log");
      let log_file_name = log_dir_buf.to_str().unwrap();
  
      let log_file = OpenOptions::new()
                          .create(true)
                          .write(true)
                          .truncate(true)
                          .open(log_file_name).unwrap();
  
      let console_drain = slog_term::streamer().build();
      let file_drain = slog_stream::stream(log_file, slog_json::default());
      let logger = slog::Logger::root(slog::duplicate(console_drain, file_drain).fuse(), o!());
      slog_stdlog::set_logger(logger).unwrap();
  } 
  
  fn main() {
      init_logger(Path::new("."));
  
      info!("This is an info message");
      warn!("This is a warn message");
      error!("This is an error message");
      debug!("This is a debug message");
  }
  </code></pre>
  
  <p>Now, building a release version as stated above and running the binary I get the following output:</p>
  
  <pre><code>Jan 23 17:20:56.640 INFO This is an info message
  Jan 23 17:20:56.641 WARN This is a warn message
  Jan 23 17:20:56.641 ERRO This is an error message
  Jan 23 17:20:56.641 DEBG This is a debug message
  </code></pre>
  
  <p>Finally, rust version:
  <code>rustc 1.31.0 (abe02cefd 2018-12-04)</code></p>
  
  <p>I know the version of slog I'm using is old, but upgrading the dependency is not a priority at the moment. However, the <a href="https://docs.rs/slog/1.5.0/slog/#notable-details" rel="nofollow noreferrer">version's documentation</a> states that log filtering should be possible as @shepmaster describes in the <a href="https://stackoverflow.com/questions/34538397/is-it-possible-to-change-the-log-level-for-an-application-at-compile-time">linked answer</a>, it just doesn't seem to work for me. What am I missing?</p>