[SOLVED]Laravel 7.x Production Not Logging HTTP 500 Exception

Published

There seems to be a long standing issue around Laravel not logging correctly on production environment. I have a small application using Docker-compose to make web, queue, and scheduler, services. Testing the small app on production (which has no users currently, so I can do some breaking debugging without worrying much) , I got an HTTP 500 error trying to access a page. Checking My web/laravel.log file, there was no outputs in the past month. I tried deleting the log file, And hit the page’s 500 error again . No file created.

Going into the Web Service container and running tinker and executing the following:

Log::debug("HELLO, World?");

Created the Web/Laravel.log file with text a line

[2020-08-19 17:51:36] production.DEBUG: HELLO, World?

So a few things :

  1. Every docker rebuild, my Cache, Configuration, etc. are rebuilt from The base project on the host, and the containers only volumes are for the log file, so It’s likely not an issue with cacheing or resetting (As I’ll explain below).
  2. The fact that Log::debug("message") works as intended indicates that it’s not a PATH issue, and not a Permissions issue.
  3. I just had to do a bunch of debugging with my Queue service , during which I used the Queue/laravel.log file a lot. The Queue Service logged exceptions without issue, as far as I could tell. Since the Queue Service and Web Services are made from the exact same base project, with the exact same steps, only difference being the Execution Commands.
  4. I tried on my development environment changing the APP_DEBUG and APP_ENV to false and production respectively, And still got correct output on my development environment.

And there seems to be a lot of other forms with this same problem , none of which gave a proper solution. Using This Thread I was able to see the error message

"Property [permissioned_users] does not exist on this collection instance."

Which was then very easy to find the issue and solve . However if I get a 500 Issue in the future, I want it to log so I know what’s going on, So I’d like to fully solve this and get to the bottom of it.
The following threads on this issue do not give official solutions:
Laravel log errors in production
Laravel 5.8 Log levels are not working
App Debug Not Working in Laravel 5.8
Log info not working
Laravel 5.3 Logging not working

Many of these older solutions give advice to set "APP_LOG_LEVEL" , Which seems to have been depreciated in Laravel 5.6 . ( Unrelated – Reimplementation of this here? )

For now, My solution seems to be something like adding the following line to the AppExceptionHandler line 37 (Instead of the above dd($e->getMessage() that helped me debug in the first place):

if(config('app.env') == "production" && env('CONTAINER_ROLL') == "web-server"){ Log::error("PRODUCTION WEB EXCEPTION : " . $exception->getMessage()); }

But I’d rather figure out the underlying issue and fully solve this problem .

EDIT : While writing this message, I discovered the underlying issue (Permission issue). See below for my specific (Docker) issue

Source: StackOverflow

Published
Categorised as docker, docker-compose, laravel, logging, permissions

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq