Using configureMonologUsing after Laravel 5.7 upgrade - Supervisor Logging Permission
Asked Answered
O

1

0

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?

Ottava answered 24/2, 2019 at 19:34 Comment(1)
https://mcmap.net/q/87256/-laravel-daily-log-created-with-wrong-permissions - This solved my issue!Ottava
O
7

Taken from https://mcmap.net/q/87256/-laravel-daily-log-created-with-wrong-permissions

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.

Ottava answered 17/3, 2019 at 11:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.