title: Redirect console.log output to file
body: <p>This should be a trivial question but I don't seem to get my mind around it. Is there any simple way to just redirect all my <code>console.log</code> output to a file? <code>console.log</code> formats the objects provided in a way that is nice and interacts properly with objects that are not trivial JSONable objects.</p>
  
  <p>For example, if I do</p>
  
  <pre><code>var myerr = new Error('There has been an error');
  console.log(myerr);
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>[Error: There has been an error.]
  </code></pre>
  
  <p>While if I just do</p>
  
  <pre><code>process.stdout.write(JSON.stringify(myerr));
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>{}
  </code></pre>
  
  <p>And if I do</p>
  
  <pre><code>process.stdout.write(myerr.toString());
  </code></pre>
  
  <p>I get</p>
  
  <pre><code>Error: There has been an error
  </code></pre>
  
  <p>So if I override my <code>console.log</code> with a function that loops on its arguments with any of the tricks above and redirects the output to a file the log will not be exactly the same. </p>
  
  <p>So I wonder: what does <code>console.log</code> do to process the objects it is provided with before outputting them to the console? It just calls <code>.toString()</code> on every object, wraps things with <code>[]</code> and sends everything to <code>process.stdout.write</code>? Or does it do some other kind of preprocessing?</p>