1

Following the instruction here: Laravel Lumen change log file name

I am still getting the following error on a server where I cannot write to /storage/logs

PHP Fatal error:  Uncaught exception 'UnexpectedValueException' with message 'The stream or file "/home/app/lumen-app/storage/logs/lumen.log" could not be opened: failed to open stream: Permission denied' in /home/app/lumen-app/vendor/monolog/monolog/src/Monolog/Handler/StreamHandler.php:97
Stack trace:
#0 /home/app/lumen-app/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(37): Monolog\Handler\StreamHandler->write(Array)

I have placed the following code in bootstrap/app.php

$app->configureMonologUsing(function(Monolog\Logger $monolog) use($logPath){

$handler = (new \Monolog\Handler\StreamHandler(storage_path($logPath)))
    ->setFormatter(new \Monolog\Formatter\LineFormatter(null, null, true, true));

return $monolog->pushHandler($handler);
});

where $logPath = __DIR__.'/../../../logs/lumen-app.log'; for some reason its not picking this up.

Second note: i am receiving this error while running a artisan commnd. Within artisan command scripts - there are a lot of things in app that goes missing that are not available if the program booted normal. Is there another way to log this properly?

Community
  • 1
  • 1
azngunit81
  • 1,574
  • 2
  • 20
  • 38
  • 2
    If your $logPath is an absolute path - you should remove storage_path(), because storage_path() expects a path within the storage folder. Also, stuff like ../../../ is awfully unreadable :) – Denis Mysenko Jun 01 '16 at 00:10
  • @DenisMysenko unfortunately that didn't work and it still going back to the wrong path. However I believe the key to resolve this is if you know how to ensure the monolog's path of whatever is causing this is trapped in the artisan console command properly. For some reason if this actually worked in controllers - its not working for commands. – azngunit81 Jun 01 '16 at 02:35
  • I had almost identical code to what is in the question, but my path was an absolute one and what @DenisMysenko suggested worked for me. – The Unknown Dev Sep 27 '17 at 19:45

0 Answers0