title: How to ship logs in a microservice architecture with docker?
body: <p>Heroku describes logs in its <a href="http://12factor.net/" rel="noreferrer">Twelve-Factor App manifest</a> as simple event streams:</p>
  <blockquote>
  <p>Logs are the stream of aggregated, time-ordered events collected from the output streams of all running processes and backing services. Logs in their raw form are typically a text format with one event per line (though backtraces from exceptions may span multiple lines). Logs have no fixed beginning or end, but flow continuously as long as the app is operating.</p>
  </blockquote>
  <p>Additionally, apps should simply write logs to <code>stdout</code>, leaving the task to the &quot;environment&quot;.</p>
  <blockquote>
  <p>A twelve-factor app never concerns itself with routing or storage of its output stream. It should not attempt to write to or manage logfiles. Instead, each running process writes its event stream, unbuffered, to stdout. During local development, the developer will view this stream in the foreground of their terminal to observe the app’s behavior.</p>
  <p>In staging or production deploys, each process’ stream will be captured by the execution environment, collated together with all other streams from the app, and routed to one or more final destinations for viewing and long-term archival. These archival destinations are not visible to or configurable by the app, and instead are completely managed by the execution environment. Open-source log routers (such as Logplex and Fluent) are available for this purpose.</p>
  </blockquote>
  <p>So what's the best way to achieve this in a docker environment in terms of reliability, efficiency and ease of use? I think the following questions come to mind:</p>
  <ul>
  <li>Is it safe to rely on Docker's own log facility (<code>docker logs</code>)?</li>
  <li>Is it safe to run docker undetached and consider its output as the logging stream?</li>
  <li>Can <code>stdout</code> be redirected to a file directly (disk space)?</li>
  <li>If using a file, should it be inside the docker image or a bound volume (<code>docker run --volume=[]</code>)?</li>
  <li>Is logrotation required?</li>
  <li>Is it safe to redirect stdout directly into a logshipper (and which logshipper)?</li>
  <li>Is a named pipe (aka FIFO) an option?</li>
  <li>(more questions?)</li>
  </ul>