phplaravelloggingsupervisord

Laravel Log Facade Writes NULL Binary To laravel.log instead of logs


When calling log methods from the Log facade, it is writing binary data with the value NULL repeatedly to the laravel.log file.

I have tried several variations of calling the Log facade with the same result:

        Log::channel('stack')->info("test");
        Log::channel("single")->info('test');
        Log::debug("test");

The output in the laravel.log file is shown in the attached screenshot

enter image description here

I tried commenting out all channels in the logging.php file and am getting the same result.

Here is the uncommented version of the logging.php file


<?php

use Monolog\Handler\NullHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\SyslogUdpHandler;

return [

    /*
    |--------------------------------------------------------------------------
    | Default Log Channel
    |--------------------------------------------------------------------------
    |
    | This option defines the default log channel that gets used when writing
    | messages to the logs. The name specified in this option should match
    | one of the channels defined in the "channels" configuration array.
    |
    */

    'default' => env('LOG_CHANNEL', 'stack'),

    /*
    |--------------------------------------------------------------------------
    | Log Channels
    |--------------------------------------------------------------------------
    |
    | Here you may configure the log channels for your application. Out of
    | the box, Laravel uses the Monolog PHP logging library. This gives
    | you a variety of powerful log handlers / formatters to utilize.
    |
    | Available Drivers: "single", "daily", "slack", "syslog",
    |                    "errorlog", "monolog",
    |                    "custom", "stack"
    |
    */

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['single']
        ],

        'single' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],

        'stdout' => [
            'driver' => 'monolog',
            'handler' => StreamHandler::class,
            'with' => [
                'stream' => 'php://stdout',
            ],
        ],

        'daily' => [
            'driver' => 'daily',
            'path' => storage_path('logs/datadog.laravel.log'),
            'level' => 'debug',
            'days' => 14,
        ],
        'slack' => [
            'driver' => 'slack',
            'url' => env('LOG_SLACK_WEBHOOK_URL'),
            'username' => 'Laravel Log',
            'emoji' => ':boom:',
            'level' => 'critical',
        ],

        'papertrail' => [
            'driver' => 'monolog',
            'level' => 'debug',
            'handler' => SyslogUdpHandler::class,
            'handler_with' => [
                'host' => env('PAPERTRAIL_URL'),
                'port' => env('PAPERTRAIL_PORT'),
            ],
        ],

        'stderr' => [
            'driver' => 'single',
            'path' => storage_path('logs/laravel.log'),
            'level' => 'debug',
        ],

        'syslog' => [
            'driver' => 'syslog',
            'level' => 'debug',
        ],

        'errorlog' => [
            'driver' => 'errorlog',
            'level' => 'debug',
        ],

        'null' => [
            'driver' => 'monolog',
            'handler' => NullHandler::class,
        ],

        'emergency' => [
            'path' => storage_path('logs/laravel.log'),
        ],

        'cloudwatch' => [
            'driver' => 'custom',
            'name' => env('CLOUDWATCH_LOG_NAME', 'nova_api_laravel_logs'),
            'region' => env('CLOUDWATCH_LOG_REGION', 'us-west-2'),
            'credentials' => [
                'key' => env('AWS_ACCESS_KEY_ID', ''),
                'secret' => env('AWS_SECRET_ACCESS_KEY', '')
            ],
            'stream_name' => env('CLOUDWATCH_LOG_STREAM_NAME', 'datadog.laravel.log'),
            'retention' => env('CLOUDWATCH_LOG_RETENTION_DAYS', 14),
            'group_name' => env('CLOUDWATCH_LOG_GROUP_NAME', '/ecs/nova-api/app'),
            'version' => env('CLOUDWATCH_LOG_VERSION', 'latest'),
            'formatter' => JsonFormatter::class,
            'disabled' => env('DISABLE_CLOUDWATCH_LOG', false),
            'via' => \Pagevamp\Logger::class,
        ],
    ],

];

I am not sure if we can decode this or not.

We are running supervisord with Laravel 8


Solution

  • Because supervisord was writing to the laravel.log file, it was sending tons of binary data. After removing the path of the logfile from the supervisor.properties so it couldn't write to laravel.log for the docker container, and rebuilding the docker container, it worked.

    [program:nova-api-worker]
    process_name=%(program_name)s_%(process_num)02d
    # the timeout value must be slightly shorter than the retry_at so it doesn't try to run jobs twice each time
    # a retry happens. default timeout is 60 seconds so we are overriding this to longer
    command=php /var/www/html/artisan queue:listen --timeout=3595
    autostart=true
    autorestart=true
    stopasgroup=true
    killasgroup=true
    numprocs=3
    user=root
    redirect_stderr=true
    stdout_logfile=/var/www/html/storage/logs/worker.log
    stopwaitsecs=3600
    
    [supervisord]
    logfile=/var/www/html/storage/logs/supervisord.log ; main log file; default $CWD/supervisord.log
    logfile_maxbytes=5MB         ; max main logfile bytes b4 rotation; default 50MB
    logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
    loglevel=info                ; log level; default info; others: debug,warn,trace
    pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
    nodaemon=true               ; start in foreground if true; default false
    minfds=1024                  ; min. avail startup file descriptors; default 1024
    minprocs=200                 ; min. avail process descriptors;default 200
    
    [program:php-fpm]
    command = /usr/local/sbin/php-fpm
    autostart=true
    autorestart=true
    priority=5
    # stdout_logfile=/var/www/html/storage/logs/laravel.log
    stdout_logfile_maxbytes=0
    # stderr_logfile=/var/www/html/storage/logs/laravel.log
    stderr_logfile_maxbytes=0