Home » Php » php – Is there a way to Log my errors on a LIVE hosting/production server?

php – Is there a way to Log my errors on a LIVE hosting/production server?

Posted by: admin February 25, 2020 Leave a comment

Questions:

I built a Web App using PHP and Laravel. I’ve tested the app relentlessly for a long time now and everything works great on my local computer. In my .env file, AppDebug is set to true and in the documentation, it says to make sure on a LIVE hosting/production environment that it should be set to false. After setting it to false, the problem is now, my client is going through the app himself to test it out and when he creates a Game, which is just a simple Form with a few input fields and clicks the Submit button, he gets a 500 Server error. The weird thing is that the game is still being inserted into the database, even though he receives this error. If I put the AppDebug back to true, there is no 500 error message anymore and everything works as it should, but I cannot leave it set to true. And a 500 server error is not giving me enough of a description in order for me to debug this. So how can I debug this. Do errors in Laravel get logged somewhere that would be more descriptive in the error?

How to&Answers:

What I generally use is Telescope: https://laravel.com/docs/6.x/telescope

You have to change some things to get the errors in production:
In telescopeServiceProvider change this:

Telescope::filter(function (IncomingEntry $entry) {
   if ( $this->app->isLocal()) {
      return true;
   }
   ...
}

To this:

Telescope::filter(function (IncomingEntry $entry) {
   return true; //this will prevent the condition of checking if is in local
   if ( $this->app->isLocal()) {
      return true;
   }
   ...
}

But, you can see all the errors in /storage/logs as the others stated
Cheers!