From 77ccec337eecaa7081e556500e15ff266442133a Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 26 Sep 2024 16:29:07 +0545 Subject: [PATCH 1/2] Fix: Logger throwing fatal error --- app/controllers/general.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 0bbfa2b694..d86c5683e8 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -863,8 +863,12 @@ App::error() $isProduction = System::getEnv('_APP_ENV', 'development') === 'production'; $log->setEnvironment($isProduction ? Log::ENVIRONMENT_PRODUCTION : Log::ENVIRONMENT_STAGING); - $responseCode = $logger->addLog($log); - Console::info('Log pushed with status code: ' . $responseCode); + try { + $responseCode = $logger->addLog($log); + Console::info('Log pushed with status code: ' . $responseCode); + } catch (Throwable $th) { + Console::error('Error pushing log: ' . $th->getMessage()) + } } /** Wrap all exceptions inside Appwrite\Extend\Exception */ From d4b480b0146f5036c8a0667cbdcf72a33d9e03b2 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Thu, 26 Sep 2024 16:36:51 +0545 Subject: [PATCH 2/2] catch error pushing error logs everywhere --- app/cli.php | 8 ++++++-- app/controllers/general.php | 4 ++-- app/http.php | 8 ++++++-- app/realtime.php | 8 ++++++-- app/worker.php | 8 ++++++-- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/cli.php b/app/cli.php index ecff5180a2..23502ec402 100644 --- a/app/cli.php +++ b/app/cli.php @@ -197,8 +197,12 @@ CLI::setResource('logError', function (Registry $register) { $isProduction = System::getEnv('_APP_ENV', 'development') === 'production'; $log->setEnvironment($isProduction ? Log::ENVIRONMENT_PRODUCTION : Log::ENVIRONMENT_STAGING); - $responseCode = $logger->addLog($log); - Console::info('Usage stats log pushed with status code: ' . $responseCode); + try { + $responseCode = $logger->addLog($log); + Console::info('Error log pushed with status code: ' . $responseCode); + } catch (Throwable $th) { + Console::error('Error pushing log: ' . $th->getMessage()); + } } Console::warning("Failed: {$error->getMessage()}"); diff --git a/app/controllers/general.php b/app/controllers/general.php index d86c5683e8..04554a940e 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -865,9 +865,9 @@ App::error() try { $responseCode = $logger->addLog($log); - Console::info('Log pushed with status code: ' . $responseCode); + Console::info('Error log pushed with status code: ' . $responseCode); } catch (Throwable $th) { - Console::error('Error pushing log: ' . $th->getMessage()) + Console::error('Error pushing log: ' . $th->getMessage()); } } diff --git a/app/http.php b/app/http.php index 7e1291142b..bec772c770 100644 --- a/app/http.php +++ b/app/http.php @@ -298,8 +298,12 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo $isProduction = System::getEnv('_APP_ENV', 'development') === 'production'; $log->setEnvironment($isProduction ? Log::ENVIRONMENT_PRODUCTION : Log::ENVIRONMENT_STAGING); - $responseCode = $logger->addLog($log); - Console::info('Log pushed with status code: ' . $responseCode); + try { + $responseCode = $logger->addLog($log); + Console::info('Error log pushed with status code: ' . $responseCode); + } catch (Throwable $th) { + Console::error('Error pushing log: ' . $th->getMessage()); + } } Console::error('[Error] Type: ' . get_class($th)); diff --git a/app/realtime.php b/app/realtime.php index b8fdb2cf21..39e00f7dda 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -184,8 +184,12 @@ $logError = function (Throwable $error, string $action) use ($register) { $isProduction = System::getEnv('_APP_ENV', 'development') === 'production'; $log->setEnvironment($isProduction ? Log::ENVIRONMENT_PRODUCTION : Log::ENVIRONMENT_STAGING); - $responseCode = $logger->addLog($log); - Console::info('Realtime log pushed with status code: ' . $responseCode); + try { + $responseCode = $logger->addLog($log); + Console::info('Error log pushed with status code: ' . $responseCode); + } catch (Throwable $th) { + Console::error('Error pushing log: ' . $th->getMessage()); + } } Console::error('[Error] Type: ' . get_class($error)); diff --git a/app/worker.php b/app/worker.php index 9bcdae78e6..6078a0127c 100644 --- a/app/worker.php +++ b/app/worker.php @@ -346,8 +346,12 @@ $worker $isProduction = System::getEnv('_APP_ENV', 'development') === 'production'; $log->setEnvironment($isProduction ? Log::ENVIRONMENT_PRODUCTION : Log::ENVIRONMENT_STAGING); - $responseCode = $logger->addLog($log); - Console::info('Usage stats log pushed with status code: ' . $responseCode); + try { + $responseCode = $logger->addLog($log); + Console::info('Error log pushed with status code: ' . $responseCode); + } catch (Throwable $th) { + Console::error('Error pushing log: ' . $th->getMessage()); + } } Console::error('[Error] Type: ' . get_class($error));