title: Linux/c++ log rotation scheme
body: <p>I have a logger system which basically is a fancy way of writing my data to std::clog in a thread safe way. </p>
  
  <p>I also, redirect <code>std::clog</code> to a file like this:</p>
  
  <pre><code>int main() {
      std::ofstream logfile(config::logname, std::ios::app);
      std::streambuf *const old_buffer = std::clog.rdbuf(logfile.rdbuf());
  
      // .. the guts of the application
  
      std::clog.rdbuf(old_buffer);
  }
  </code></pre>
  
  <p>This works great... however, my application also produces a very large amount of logs. I was wondering what would be a good way to properly rotate my log files. Is there a safe way to switch out the file via a cron task? I would guess no.</p>
  
  <p>The only thing I can think of that would definitely work is if I had the application itself open a new file, and redirect the rdbuf of clog to that while holding the logging mutex. But that feels like a cheap solution, and I would need to check so see if it is time to rotate logs fairly often for it to be effective. There has got to be a better way.</p>