title: How do I change the log level of a running process with log4rs?
body: <p>I am trying to change log-level dynamically during the run of my Rust program. </p>
  
  <p>I used log4rs as in <a href="https://github.com/estk/log4rs/blob/master/examples/log_to_file.rs#L47" rel="nofollow noreferrer">their example</a> they claimed it's possible.</p>
  
  <p>But when I run the following program it crashes - when I try to change the log level - and I think it's a restriction of the log API (according to that: <a href="https://github.com/rust-lang/log/blob/master/src/lib.rs#L1278" rel="nofollow noreferrer">https://github.com/rust-lang/log/blob/master/src/lib.rs#L1278</a>) </p>
  
  <p>Is there anyway other way that I could change the log-level in runtime? </p>
  
  <p>Here is what I am trying to do:   </p>
  
  <pre><code>use log4rs::append::console::ConsoleAppender;
  use log4rs::append::console::Target;
  use log4rs::config::{Appender, Config, Root}; 
  
  use log::*;
  
  fn main() {
      let level_info = log::LevelFilter::Info; 
      let level_trace = log::LevelFilter::Trace;
  
  
      let stderr = ConsoleAppender::builder().target(Target::Stderr).build();
      let config = Config::builder().appender(
          Appender::builder()
              .build("stderr", Box::new(stderr)),
      ).build(
          Root::builder()
              .appender("stderr")
              .build(level_info),
      ).unwrap();
  
      log4rs::init_config(config).unwrap(); 
  
  
      error!("error"); //should print 
      warn!("warn");   //should print
      info!("info");   //should print
      debug!("debug"); //should  not print
      trace!("trace"); //should  not print 
  
  
      let stderr = ConsoleAppender::builder().target(Target::Stderr).build();
      let config = Config::builder().appender(
          Appender::builder()
              .build("stderr", Box::new(stderr)),
      ).build(
          Root::builder()
              .appender("stderr")
              .build(level_trace),
      ).unwrap();
  
      log4rs::init_config(config).unwrap(); 
  
  
      error!("error2"); //should print
      warn!("warn2");   //should print
      info!("info2");   //should print
      debug!("debug2"); //should print
      trace!("trace2"); //should print  
  
  }
  </code></pre>
  
  <p>The output:</p>
  
  <pre class="lang-none prettyprint-override"><code>2020-04-20T12:07:53.351080400+01:00 ERROR use_log4rs - error
  2020-04-20T12:07:53.354078400+01:00 WARN use_log4rs - warn
  2020-04-20T12:07:53.356077200+01:00 INFO use_log4rs - info
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: SetLoggerError(())', src\main.rs:48:5
  </code></pre>