From a0b79f22879bac8012186059f36d3ec1bef07911 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Wed, 31 May 2023 13:27:00 +0300 Subject: [PATCH] added logs --- app/Http/Controllers/WebCrawlController.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/Http/Controllers/WebCrawlController.php b/app/Http/Controllers/WebCrawlController.php index f62035b..379b2d7 100644 --- a/app/Http/Controllers/WebCrawlController.php +++ b/app/Http/Controllers/WebCrawlController.php @@ -5,6 +5,7 @@ use App\Models\WebCrawl; use GuzzleHttp\Client; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; class WebCrawlController extends Controller { @@ -25,6 +26,7 @@ public function crawlWebsite(Request $request) // Check if the URL is already in the database $webCrawl = WebCrawl::where('url', $url)->first(); if ($webCrawl && !$refresh) { + Log::error("This URL already exists in the database $url"); return response()->json([ 'error' => 'This URL already exists in the database', ], 400); @@ -42,6 +44,7 @@ public function crawlWebsite(Request $request) try { $crawler->save(); } catch (\Exception $e) { + Log::error($e->getMessage()); return response()->json([ 'error' => 'Failed to save the URL to the database', ], 500); @@ -57,11 +60,13 @@ public function crawlWebsite(Request $request) ]); } } else { + Log::error("Failed to retrieve the URL $url"); return response()->json([ 'error' => 'Failed to retrieve the URL', ], 500); } + Log::info("Crawling completed successfully For URL $url"); return response()->json([ 'message' => 'Crawling completed successfully', ]); @@ -84,7 +89,9 @@ protected function crawlWebsiteRecursive($url, $depth) $linksFromPage = $this->getLinksFromPage($crawler->content); try { $crawler->save(); + Log::info("URL saved to the database $url"); } catch (\Exception $e) { + Log::error("Can't save the URL to the database $url"); return []; } if ($depth > 0 && count($linksFromPage) > 0) { @@ -124,10 +131,12 @@ public function destroy($id) $webCrawl = WebCrawl::find($id); if ($webCrawl) { $webCrawl->delete(); + Log::info("Web crawl deleted successfully For ID $id"); return response()->json([ 'message' => 'Web crawl deleted successfully', ]); } + Log::error("Web crawl not found For ID $id"); return response()->json([ 'error' => 'Web crawl not found', ], 404); @@ -136,6 +145,7 @@ public function destroy($id) public function destroyAll() { WebCrawl::truncate(); + Log::info("All web crawls deleted successfully"); return response()->json([ 'message' => 'All web crawls deleted successfully', ]);