0

It seems that the issue I am facing is straightforward but somehow the resolutions suggested here, here, and here are not working

I have got the following piece of code:

namespace App\Traits;

use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;

...

try {

  $response = Http::timeout(3)->get('google.cim');

} catch (\Illuminate\Http\Client\ConnectionException $e) {

  Log::info('Connection refused #6 ');

}

I have already tried

  1. Using \Illuminate\Http\Client\ConnectionException $e
  2. Using \Exception $e
  3. Clearing cache php artisan optimize:clear

But I just see the exception in the logs while my custom message never appears in the log.

Thank you.

11
  • 1
    Have you reviewed the stack trace from the error log to see if the error is being generated/logged somewhere you're not expecting? The above code is working as expected in isolation (i.e. your custom message is logged). Commented Aug 17, 2022 at 11:08
  • @Peppermintology thank you for trying to help me out... if it works for you then my suspicion of cache being the culprit becomes stronger but alas even clearing them don't work on my end. To answer your question, I am looking at the same log where all my other custom logging is being done which is storage/logs/laravel.log Commented Aug 17, 2022 at 11:24
  • Sorry, when I say generated/logged somewhere you're not expecting, I mean in your code. So the or a similar exception is being thrown somewhere other than the above code. Commented Aug 17, 2022 at 11:26
  • 1
    You can easily debug it, just add a dd("works") just before your Http::get, and see if it works. Commented Aug 17, 2022 at 12:57
  • 1
    thanks @BernardWiesner ... the solution I found disappointingly can't really be called one as it was a cache issue after all... it was resolved only after I restarted everything (including the machine). Your suggestion of adding dd (although I used a log) helped me though. Commented Aug 18, 2022 at 3:49

1 Answer 1

0

Rather than catching a specific exception, try catching all exceptions using:

try {
    $response = Http::timeout(3)->get('google.cim');
} catch (\Exception $e) {
    Log::info($e->getMessage()); 
}

Also, check your config/logging.php file to make sure your logging level is set correctly. It should be debug or info:

'daily' => [
    'driver' => 'daily',
    'path' => storage_path('logs/laravel.log'),
    'level' => 'debug',
    'days' => 14,
],

Don't forget to clear the config cache if you need to make change. Run: php artisan config:clear.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks for your time... however there was nothing in your reply that I haven't already tried and I mentioned it too in my comment except for explicitly checking the logs settings which was anyway implicitly confirmed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.