Laravel Log Facade将NULL二进制文件写入laravel.log而不是logs

byqmnocz  于 2023-10-22  发布在  其他
关注(0)|答案(1)|浏览(106)

当从Log facade调用log方法时,它会将值为NULL的二进制数据重复写入laravel.log文件。
我尝试了几种调用Log facade的变体,结果都是一样的:

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

laravel.log文件中的输出显示在随附的屏幕截图中

我尝试注解掉logging.php文件中的所有通道,得到了相同的结果。
下面是logging.php文件的未注解版本

<?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,
        ],
    ],

];

我不确定我们是否能解码。
我们正在使用Laravel 8运行supervisord

rkue9o1l

rkue9o1l1#

因为supervisord正在写入laravel.log文件,所以它发送了大量的二进制数据。从www.example.com中删除日志文件的路径supervisor.properties,使其无法写入docker容器的laravel.log,并重建docker容器后,它工作了。

[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

相关问题