Logging not working in laravel queue job

后端 未结 3 1852
情书的邮戳
情书的邮戳 2021-02-02 02:10

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         


        
3条回答
  •  别那么骄傲
    2021-02-02 02:33

    Based on @PrabhatRai answer, here is another configuration example that looks more like Laravel's default behavior.

    Add this code to bootstrap/app.php:

    $app->configureMonologUsing(function (Monolog\Logger $monolog) {
        $filename = storage_path('logs/' . php_sapi_name() . '-' . posix_getpwuid(posix_geteuid())['name'] . '.log');
        $monolog->pushHandler($handler = new Monolog\Handler\RotatingFileHandler($filename, 30));
        $handler->setFilenameFormat('laravel-{date}-{filename}', 'Y-m-d');
        $handler->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true));
    });
    
    • It will store files like this: laravel-2017-03-27-cli-raph.log and laravel-2017-03-27-fpm-cgi-raph.log which is more readable.
    • New lines are preserved (as of default Laravel behavior)
    • It works with Laravel Log Viewer

提交回复
热议问题