Skip to content
Advertisement

log to stdout / stderr with Laravel 5.6 and php-fpm

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 stdout (stderr is also fine by me) under php-fpm. The php version is 7.2.1, the laravel version is 5.6.3.

I configured laravel to use the single driver to write to stdout:

<?php

return [
    'default' => env('LOG_CHANNEL', 'stack'),
    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single'],
        ],

        'single' => [
            'driver' => 'single',
            'path' => 'php://stdout',
            'tap' => [AppLoggingUseJsonFormatter::class],
            'level' => 'debug',
        ],
];

This works well with the test server, but fpm prefixes this with with dates and a warning: [19-Feb-2018 09:43:41] WARNING: [pool www] child 12 said into stdout: every ~1000 characters. The problem seems to be known as issue 71880 (prefix) and issue 69031 (truncation). A Pull Request 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)?

Why PHP-FPM prefixes a warning when writing to stdout? is related to this, but is still not solved either.

This is UseJsonFormatter.php if anyone is interested:

<?php    
namespace AppLogging;


use MonologFormatterJsonFormatter;

class UseJsonFormatter
{
    /**
     * Customize the given Monolog instance.
     *
     * @param  MonologLogger  $monolog
     * @return void
     */
    public function __invoke($monolog)
    {
        $jsonFormatter = new JsonFormatter();
        foreach ($monolog->getHandlers() as $handler) {
            $handler->setFormatter($jsonFormatter);
        }
    }
}

Advertisement

Answer

This is fixed in PHP 7.3. The config directive for the pool is decorate_workers_output = no as documented in the pull request.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement