日志在 laravel 队列作业中不起作用 [英] Logging not working in laravel queue job

查看:47
本文介绍了日志在 laravel 队列作业中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 supervisor/conf.d/myconf.conf 文件中有以下设置:

[program:my-worker]process_name=%(program_name)s_%(process_num)02dcommand=php/var/www/html/artisan queue:work sqs --queue=my_queue_name --tries=3 --daemon自动启动=真自动重启=真用户=根numprocs=1重定向标准错误=真stdout_logfile=/var/www/html/storage/logs/mylogfile.log

我已授予 storage/logs/mylogfile.log 文件的所有权限.无法弄清楚为什么它仍然没有记录,

解决方案

我猜你用的是每日日志.

当我们有一个日志文件时,我们有一个日志文件:laravel.log",我们给予完全权限 [777],这样我们就可以登录并且一切都按预期进行.

但是当我们选择了每日文件时,laravel 应用程序每天都会在需要记录某些内容时创建一个新文件.现在这个文件的所有者是 web 服务器 (daemon/www-root),因为 laravel 是由用户 daemon/www-root 运行的.

当队列被处理时,用户是cli",它没有写入这个文件的权限.所以它抛出一个异常并且处理停止.

如果您使用每日日志,我建议您更改独白设置,以便为不同的用户创建不同的日志文件.

将此代码添加到 bootstrap/app.php

/*** 配置独白.*/$app->configureMonologUsing(function(MonologLogger $monolog) {$processUser = posix_getpwuid(posix_geteuid());$processName= $processUser['name'];$filename = storage_path('logs/laravel-' . php_sapi_name() . '-' . $processName . '.log' );$handler = new MonologHandlerRotatingFileHandler( $filename );$monolog->pushHandler($handler);});

就在返回应用程序之前.

现在您也将拥有 cli 的日志文件,并且与队列相关的所有内容都将记录在该文件中.

这也使日志文件保持干净.HTTP 应用程序日志将在不同的文件中,队列处理日志将在不同的文件中.

另外请不要忘记运行以下命令.

<块引用>

确保正确加载新配置

php artisan config:clear

<块引用>

由于您使用的是主管守护进程队列工作者,因此您需要广播队列重启信号.

php artisan queue:restart

希望这会有所帮助.

I have the below settings in my supervisor/conf.d/myconf.conf file :

[program:my-worker]    
process_name=%(program_name)s_%(process_num)02d    
command=php /var/www/html/artisan queue:work sqs --queue=my_queue_name --tries=3 --daemon    
autostart=true    
autorestart=true    
user=root    
numprocs=1    
redirect_stderr=true    
stdout_logfile=/var/www/html/storage/logs/mylogfile.log

I have give all permissions to storage/logs/mylogfile.log file. Not able to figure out why is it still not logging,

解决方案

I guess you are using Daily logs.

When we have single log file then we have one log file : "laravel.log" which we give full permission [777], so we are able to log and everything works as expected.

But when we have daily file selected then each day the laravel app will create a new file whenever it needs to log something. Now this file's owner is the web server (daemon/www-root) because laravel is run by the user daemon/www-root.

When the queue is getting processed the user in action is "cli", and it does not have permission to write to this file. so it throws an exception and the processing stops.

What I would suggest to do if you are using daily logs is change monolog settings so that for different users different log files will be created.

Add this code to bootstrap/app.php

/**
 * Configure Monolog.
 */
$app->configureMonologUsing( function( MonologLogger $monolog) {
    $processUser = posix_getpwuid( posix_geteuid() );
    $processName= $processUser[ 'name' ];

    $filename = storage_path( 'logs/laravel-' . php_sapi_name() . '-' . $processName . '.log' );
    $handler = new MonologHandlerRotatingFileHandler( $filename );
    $monolog->pushHandler( $handler );
});

Just before retrurning the app.

Now you will have log files for cli too, and everything related to queue will be logged in that file.

This also keeps log files clean. HTTP app logs will be in different file and the Queue processing logs will be in different file.

Also please don't forget to run following commands.

To make sure new config is loaded correctly

php artisan config:clear

As you are using supervisor daemon queue worker, so you will need to broadcast the queue restart signal.

php artisan queue:restart

Hope this helps.

这篇关于日志在 laravel 队列作业中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆