0

As we all painfully know, this message is generated when an error occurs before Laravel has had a chance to instantiate a "Log" class instance to handle it. And... it therefore seems to completely conceal just what the underlying error is!

In my case the php artisan command won't run either.

Is there any way to find out what's wrong without "blind guessing?"

Mike Robinson
  • 8,490
  • 5
  • 28
  • 41
  • most (if not all) artisan commands have a `-v` option for verbose which will produce a stack trace. – Erich Feb 10 '20 at 19:50
  • Unfortunately, say `php artisan config:cache` *does* produce a stack trace, but that trace is not helpful. It lists six entries, all within `Container.php` or `Application.php,` all apparently having to do with constructing the 'log' ReflectionClass. The `-v` option does not produce anything more. And, it doesn't tell me what *underlying* error caused Laravel to want to create a logger. – Mike Robinson Feb 10 '20 at 19:58
  • try `cache:clear` and `config:clear`. next i'd try `composer dump-autoload` – Erich Feb 10 '20 at 20:20
  • I tried all of these things. *Every* `php artisan` command fails. `composer dump-autoload` runs but does not affect the problem. I simply need to find a way to discover what the *underlying* exception was, that Laravel was trying to log. – Mike Robinson Feb 10 '20 at 20:37
  • In my case, the fact that the error "recently began to occur" led me to use `git diff --name-only` to find out which files had changed. Sure enough, there was a *syntax error,* and that's what caused it. But, really, should there not be a way to find out directly what the underlying error was?! Really??! – Mike Robinson Feb 10 '20 at 21:21
  • Take a look here and see if it helps: https://stackoverflow.com/questions/34978828/uncaught-reflectionexception-class-log-does-not-exist-laravel-5-2 – Felippe Duarte Feb 10 '20 at 21:28

2 Answers2

0

When you want to handle exceptions, a good way to catch it would be to implement a way to trapping exception out of controllers or services. You can do it in the "render" method of the App\Exceptions\Handler class. In this "render" method, you can write a block of "if" code to show the messages generated by an exception when Laravel throws an exception. For example:

 public function render($request, Exception $exception)
 {
     if($exception) {
         // do something
         return response()->json(['error' => $exception->getMessage(), 
                 $exception->getTraceAsString()], 500);
     }

     // Or if you created an exception specialization
     if ($exception instanceof MyCustomException) {
         return response()->view('errors.custom', [], 500);
     }

     return parent::render($request, $exception);
 }
Alexandre Barbosa
  • 1,194
  • 1
  • 7
  • 6
0

This was indeed caused by a syntax error, and I'm really surprised that Laravel had even managed to "get started" by that point in time. I literally found it by looking with git at a list of files that had recently changed.

Mike Robinson
  • 8,490
  • 5
  • 28
  • 41