title: log to stdout / stderr with Laravel 5.6 and php-fpm
body: <p>I want my laravel applications to run as well mannered 12 factor apps. Right now I'm struggling to get their to logs to and from <code>stdout</code> (<code>stderr</code> is also fine by me) under php-fpm. The php version is 7.2.1, the laravel version is 5.6.3.</p>
  
  <p>I configured laravel to use the <code>single</code> driver to write to stdout:</p>
  
  <pre><code>&lt;?php
  
  return [
      'default' =&gt; env('LOG_CHANNEL', 'stack'),
      'channels' =&gt; [
          'stack' =&gt; [
              'driver' =&gt; 'stack',
              'channels' =&gt; ['single'],
          ],
  
          'single' =&gt; [
              'driver' =&gt; 'single',
              'path' =&gt; 'php://stdout',
              'tap' =&gt; [App\Logging\UseJsonFormatter::class],
              'level' =&gt; 'debug',
          ],
  ];
  </code></pre>
  
  <p>This works well with the test server, but fpm prefixes this with with dates and a warning: <code>[19-Feb-2018 09:43:41] WARNING: [pool www] child 12 said into stdout:</code> every ~1000 characters.
  The problem seems to be known as <a href="https://bugs.php.net/bug.php?id=71880" rel="noreferrer">issue 71880 (prefix)</a> and <a href="https://bugs.php.net/bug.php?id=69031" rel="noreferrer">issue 69031 (truncation)</a>. A <a href="https://github.com/php/php-src/pull/2458" rel="noreferrer">Pull Request</a> saw last action in June / November last year. Does anybody have a workaround that doesn't chunk or truncate the log messages (I'm logging json objects, and I like them complete)?</p>
  
  <p><a href="https://stackoverflow.com/questions/36134167/why-php-fpm-prefixes-a-warning-when-writing-to-stdout">Why PHP-FPM prefixes a warning when writing to stdout?</a> is related to this, but is still not solved either.</p>
  
  <p>This is UseJsonFormatter.php if anyone is interested:</p>
  
  <pre><code>&lt;?php    
  namespace App\Logging;
  
  
  use Monolog\Formatter\JsonFormatter;
  
  class UseJsonFormatter
  {
      /**
       * Customize the given Monolog instance.
       *
       * @param  \Monolog\Logger  $monolog
       * @return void
       */
      public function __invoke($monolog)
      {
          $jsonFormatter = new JsonFormatter();
          foreach ($monolog-&gt;getHandlers() as $handler) {
              $handler-&gt;setFormatter($jsonFormatter);
          }
      }
  }
  </code></pre>