Laravel 5.7 升级后使用 configureMonologUsing - 主管日志记录权限

Using configureMonologUsing after Laravel 5.7 upgrade - Supervisor Logging Permission

我正在尝试将我的 Laravel 5.5 项目升级到 5.7。我使用主管,在我使用 configureMonologUsing() 生成日志之前,但显然随着 5.6 升级,它已经贬值了。我在 L5.5 中的完整代码是:在 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 );
});

它正在生成各种记录器,例如(这很方便):

  • laravel-cli-root-{date},

  • laravel-cli-ubuntu-{date},

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

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

但是,它在 upgrade guide 中说,所以我不能再使用 configureMonologUsing:

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.

我不知道如何使用日志通道实现同样的目的。我怎样才能利用 Monolog Channel 来写入 laravel/storage/logs 文件夹?

取自https://whosebug.com/a/49379249/4705339

Laravel 版本 5.6.10 及更高版本支持 singledaily 配置 (config/logging.php) 中的 permission 元素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
    ],

无需在 bootstrap 脚本中处理 Monolog。

具体来说,在 https://github.com/laravel/framework/commit/4d31633dca9594c9121afbbaa0190210de28fed8 中添加了支持。