当从
Log
门面调用日志方法时,它正在将值为NULL的二进制数据重复写入laravel.log
文件。
我尝试了多种调用
Log
外观的变体,但结果相同:
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
因为supervisord正在写入laravel.log文件,所以它发送了大量的二进制数据。从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