title: Custom application console and stderr
body: <p>I'm writing a class to display a custom console from inside the application. I'm also using <code>glog</code> to log messages to a file and at the same time to stderr. How can I have my console class listen to stderr?</p>
  
  <p>I thought of making a custom fstream and the doing something like:</p>
  
  <pre><code>CustomStream cs;
  auto original_buf = std::cerr.rdbuf(cs.rdbuf());
  </code></pre>
  
  <p>and having calls to the <code>stream operator &lt;&lt;</code> sent to the console class.</p>
  
  <p>Or subclassing directly from <code>std::filebuf</code> and calling:</p>
  
  <pre><code>CustomFilebuf fb;
  auto original_buf = std::cerr.rdbuf(&amp;fb);
  </code></pre>
  
  <p>Is this the right way to do it? I searched for some sample code but couldn't find very much.</p>
  
  <p>Edit1: I tried using stream tee, but glog logs with <code>stderr</code> and not <code>std::cerr</code>, so I wasn't able to grab any data.</p>