问题
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
MethodIf 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