Using configureMonologUsing after Laravel 5.7 upgrade - Supervisor Logging Permission

余生颓废 提交于 2019-12-12 01:13:13

问题


I am trying to upgrade my Laravel 5.5 project to 5.7. I use supervisor and before I was using configureMonologUsing() to generate the logs but apparently with 5.6 upgrade, it got depreciated. My full code in L5.5 was: in bootstrap/app.php:

$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 );
});

And it was generating various loggers like (which was convenient):

  • laravel-cli-root-{date},

  • laravel-cli-ubuntu-{date},

  • laravel-cli-www-data-{date},

  • laravel-fpm-fcgi-www-data-{date}, etc...

However, it says in the upgrade guide so I can't use configureMonologUsing any more:

The configureMonologUsing Method

If you were using the configureMonologUsing method to customize the Monolog instance for your application, you should now create a custom Log channel. For more information on how to create custom channels, check out the full logging documentation.

I couldn't figure out how to achieve the same with logging channels. How can I utilise Monolog Channel to be able to write laravel/storage/logs folder?


回答1:


Taken from https://stackoverflow.com/a/49379249/4705339

Laravel version 5.6.10 and later has support for a permission element in the configuration (config/logging.php) for the single and the daily driver:

    'daily' => [
        'driver' => 'daily',
        'path' => storage_path('logs/laravel.log'),
        'level' => 'debug',
        'days' => 7,
        'permission' => 0664,    // this line lets the file owner to be www-data:www-data
    ],

No need to juggle with Monolog in the bootstrap script.

Specifically, support was added in https://github.com/laravel/framework/commit/4d31633dca9594c9121afbbaa0190210de28fed8.



来源:https://stackoverflow.com/questions/54855725/using-configuremonologusing-after-laravel-5-7-upgrade-supervisor-logging-permi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!