From 2655241265c3669c984738a2d909f6f83638412b Mon Sep 17 00:00:00 2001 From: iglocska Date: Tue, 18 Jun 2024 13:39:38 +0200 Subject: [PATCH] new: [extended logger] added - Added more information about the request to the stack traces - logs user name / ID - logs request x-forwarded-for --- config/app.php | 1 + src/Error/ExtendedErrorLogger.php | 62 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/Error/ExtendedErrorLogger.php diff --git a/config/app.php b/config/app.php index 480c342..12b0c2a 100644 --- a/config/app.php +++ b/config/app.php @@ -177,6 +177,7 @@ return [ * breathing room to complete logging or error handling. */ 'Error' => [ + 'logger' => App\Error\ExtendedErrorLogger::class, 'errorLevel' => E_ALL, 'skipLog' => [], 'log' => true, diff --git a/src/Error/ExtendedErrorLogger.php b/src/Error/ExtendedErrorLogger.php new file mode 100644 index 0000000..30e22ef --- /dev/null +++ b/src/Error/ExtendedErrorLogger.php @@ -0,0 +1,62 @@ +getRequestTarget(); + + $referer = $request->getHeaderLine('Referer'); + if ($referer) { + $message .= "\nReferer URL: " . $referer; + } + + + if (method_exists($request, 'clientIp')) { + $clientIp = $request->clientIp(); + if ($clientIp && $clientIp !== '::1') { + $message .= "\nClient IP: " . $clientIp; + } + } + + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { + $message .= sprintf( + "\nClient X_FORWARDED_FOR: %s", + $_SERVER['HTTP_X_FORWARDED_FOR'] + ); + } + + if (!empty($request->getSession()->read('authUser'))) { + $message .= sprintf( + "\nClient user: #%s :: %s", + $request->getSession()->read('authUser.id'), + $request->getSession()->read('authUser.username') + ); + } + return $message; + } +} \ No newline at end of file