title: Is console.log atomic?
body: <p>The <code>print</code> statement in Python is not thread-safe. Is it safe to use <code>console.log</code> in Node.js concurrently? </p>
  
  <p>If so, then is it also interleave-safe? That is, if multiple (even hundreds) of callbacks write to the console, can I be sure that the output won't be clobbered or interleaved? </p>
  
  <p>Looking at the source code, it seems that Node.js queues concurrent attempts to write to a stream (<a href="https://github.com/nodejs/node/blob/master/lib/_stream_writable.js#L266" rel="nofollow noreferrer">here</a>). On the other hand, <code>console.log</code>'s <a href="https://nodejs.org/api/console.html#console_console_log_data" rel="nofollow noreferrer">substitution flags come from <code>printf(3)</code></a>. If <code>console.log</code> wraps around <code>printf</code>, then that can interleave output on POSIX machines (<a href="https://stackoverflow.com/a/467949/850206">as shown here</a>).</p>
  
  <p>Please show me where the <a href="https://github.com/nodejs/node/blob/master/lib/_stream_writable.js#L2" rel="nofollow noreferrer"><code>async ._write(chunk, encoding, cb)</code> is implemented</a> inside Node.js in your response to this question. </p>
  
  <p>EDIT: If it is fine to write to a stream concurrently, then why does <a href="https://www.npmjs.com/package/fs-write-stream-atomic" rel="nofollow noreferrer">this npm package</a> exist?</p>