日志无法在Laravel队列作业中工作 [英] Logging not working in laravel queue job

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

问题描述

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

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

我拥有对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.

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

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.

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

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.

正在处理队列时,正在使用的用户为" cli ",并且它没有写此文件的权限.因此它引发异常,并且处理停止.

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.

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

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

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

在撤消应用程序之前.

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

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

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

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

希望这会有所帮助.

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

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