From 507d3c11be81b8b2c70f3c462694fc543f5f10ed Mon Sep 17 00:00:00 2001 From: AqibYounasAtTkxel <94671546+AqibYounasAtTkxel@users.noreply.github.com> Date: Thu, 16 Feb 2023 17:48:18 +0500 Subject: [PATCH] added a log into a custom file instead of laravel.log file --- .../Api/V1/CurrikiGo/ExtractXAPIJSONController.php | 13 +++++++++---- config/logging.php | 6 ++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/V1/CurrikiGo/ExtractXAPIJSONController.php b/app/Http/Controllers/Api/V1/CurrikiGo/ExtractXAPIJSONController.php index 6fbe9ed1f..80001c8d7 100644 --- a/app/Http/Controllers/Api/V1/CurrikiGo/ExtractXAPIJSONController.php +++ b/app/Http/Controllers/Api/V1/CurrikiGo/ExtractXAPIJSONController.php @@ -54,7 +54,6 @@ public function runJob( ->where('id', '>', $max_statement_id) ->orderby('id', 'ASC') ->get(); - try { $service = new LearnerRecordStoreService(); foreach ($xapiStatements as $row) { @@ -281,13 +280,19 @@ public function runJob( } } } catch (Exception $e) { - Log::error('Summary page Cronjob crashed on row id ' . $row->id . ' - ' . $e->getMessage() . ' / Line = ' . $e->getLine()); + Log::channel('cronjob')->error('Summary page Cronjob crashed on row id ' . $row->id . ' - ' . $e->getMessage() . ' / Line = ' . $e->getLine()); + $errors = true; } } - \Log::info(date('Y-m-d h:i:s') . ' - Extract XAPI script ended'); + if($errors && $errors == true){ + return response()->json([ + 'message' => 'LRS cronjob has errors, please check LRS-Cronjob.log file.' + ], 404); + } + Log::info(date('Y-m-d h:i:s') . ' - Extract XAPI script ended'); return 'Extract XAPI JSON Cron run successfully.'; } catch (Exception $e) { - \Log::error($e->getMessage()); + Log::error($e->getMessage()); } } } diff --git a/config/logging.php b/config/logging.php index 088c204e2..b5d1f4361 100644 --- a/config/logging.php +++ b/config/logging.php @@ -47,6 +47,12 @@ 'level' => 'debug', ], + 'cronjob' => [ + 'driver' => 'single', + 'path' => storage_path('logs/LRS-Cronjob.log'), + 'level' => 'debug', + ], + 'daily' => [ 'driver' => 'daily', 'path' => storage_path('logs/laravel.log'),