title: How to implement a logger that appends to a file?
body: <p>I'm trying to implement <code>log::Log</code> such that the call to <code>log()</code> appends the message to a file. This is my logger at the moment:</p>
  
  <pre><code>pub struct MyLogger {
      loglevel: LogLevelFilter,
      logfile: Option&lt;File&gt;,
  }
  </code></pre>
  
  <p>And the implementation of log::Log:</p>
  
  <pre><code>impl Log for Logger {
      fn enabled(&amp;self, metadata: &amp;LogMetadata) -&gt; bool {
          metadata.level() &lt;= self.loglevel
      }
  
      fn log(&amp;self, record: &amp;LogRecord) {
          if self.enabled(record.metadata()) {
              let msg = format!("{}\t| {}\t| {}", record.level(), record.target(), record.args());
              self.logfile.write_all(msg.as_bytes()).unwrap();
          }
      }
  }
  </code></pre>
  
  <p>Which, understandably, fails because <code>log()</code> doesn't take a mutable reference. I can't take a mutable reference because then I wouldn't be implementing the type correctly, so what would be the idiomatic way to achieve this?</p>