From d0bea80bbc0ff0ca2a4874bfc138cc5c9559ecfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=91cze=20Bence?= Date: Tue, 26 Sep 2023 23:04:24 +0200 Subject: [PATCH] log erros into file --- src/Response/HttpResponse.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Response/HttpResponse.php b/src/Response/HttpResponse.php index 6865e53..2f22d1b 100644 --- a/src/Response/HttpResponse.php +++ b/src/Response/HttpResponse.php @@ -1,5 +1,6 @@ dbConnection->rollback(); + $this->writeErrorLog($exception); $this->render500($exception); return; } @@ -151,4 +153,15 @@ class HttpResponse } return $url; } + + private function writeErrorLog(Exception $exception): void + { + if (!isset($this->appConfig['errorLogFile'])) { + return; + } + + $logFileHandler = fopen($this->appConfig['errorLogFile'], 'a'); + fwrite($logFileHandler, '[' . (new DateTime())->format('c') . '] ' . (string)$exception . PHP_EOL); + fclose($logFileHandler); + } }