diff --git a/module/Core/src/Action/AbstractTrackingAction.php b/module/Core/src/Action/AbstractTrackingAction.php index 0d118565..34b55aba 100644 --- a/module/Core/src/Action/AbstractTrackingAction.php +++ b/module/Core/src/Action/AbstractTrackingAction.php @@ -75,7 +75,7 @@ abstract class AbstractTrackingAction implements MiddlewareInterface return $this->createResp($url->getLongUrl()); } catch (InvalidShortCodeException | EntityDoesNotExistException $e) { - $this->logger->warning('An error occurred while tracking short code.' . PHP_EOL . $e); + $this->logger->warning('An error occurred while tracking short code. {e}', ['e' => $e]); return $this->buildErrorResponse($request, $handler); } } diff --git a/module/Core/src/Action/PreviewAction.php b/module/Core/src/Action/PreviewAction.php index 9f95e884..e8b6cbda 100644 --- a/module/Core/src/Action/PreviewAction.php +++ b/module/Core/src/Action/PreviewAction.php @@ -63,7 +63,7 @@ class PreviewAction implements MiddlewareInterface $imagePath = $this->previewGenerator->generatePreview($url->getLongUrl()); return $this->generateImageResponse($imagePath); } catch (InvalidShortCodeException | EntityDoesNotExistException | PreviewGenerationException $e) { - $this->logger->warning('An error occurred while generating preview image.' . PHP_EOL . $e); + $this->logger->warning('An error occurred while generating preview image. {e}', ['e' => $e]); return $this->buildErrorResponse($request, $handler); } } diff --git a/module/Core/src/Action/QrCodeAction.php b/module/Core/src/Action/QrCodeAction.php index c410802f..26b0e2fe 100644 --- a/module/Core/src/Action/QrCodeAction.php +++ b/module/Core/src/Action/QrCodeAction.php @@ -67,7 +67,7 @@ class QrCodeAction implements MiddlewareInterface try { $this->urlShortener->shortCodeToUrl($shortCode); } catch (InvalidShortCodeException | EntityDoesNotExistException $e) { - $this->logger->warning('An error occurred while creating QR code' . PHP_EOL . $e); + $this->logger->warning('An error occurred while creating QR code. {e}', ['e' => $e]); return $this->buildErrorResponse($request, $handler); } diff --git a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php index db5d9818..b34c1bac 100644 --- a/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/AbstractCreateShortUrlAction.php @@ -57,7 +57,7 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction $longUrl = $shortUrlData->getLongUrl(); $customSlug = $shortUrlMeta->getCustomSlug(); } catch (InvalidArgumentException $e) { - $this->logger->warning('Provided data is invalid.' . PHP_EOL . $e); + $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::INVALID_ARGUMENT_ERROR, 'message' => $e->getMessage(), @@ -77,7 +77,7 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction return new JsonResponse($transformer->transform($shortUrl)); } catch (InvalidUrlException $e) { - $this->logger->warning('Provided Invalid URL.' . PHP_EOL . $e); + $this->logger->warning('Provided Invalid URL. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => \sprintf( @@ -86,7 +86,7 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction ), ], self::STATUS_BAD_REQUEST); } catch (NonUniqueSlugException $e) { - $this->logger->warning('Provided non-unique slug.' . PHP_EOL . $e); + $this->logger->warning('Provided non-unique slug. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => \sprintf( @@ -95,7 +95,7 @@ abstract class AbstractCreateShortUrlAction extends AbstractRestAction ), ], self::STATUS_BAD_REQUEST); } catch (\Throwable $e) { - $this->logger->error('Unexpected error creating short url.' . PHP_EOL . $e); + $this->logger->error('Unexpected error creating short url. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, 'message' => $this->translator->translate('Unexpected error occurred'), diff --git a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php index d752cc9b..01d6983b 100644 --- a/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/DeleteShortUrlAction.php @@ -50,14 +50,15 @@ class DeleteShortUrlAction extends AbstractRestAction return new EmptyResponse(); } catch (Exception\InvalidShortCodeException $e) { $this->logger->warning( - \sprintf('Provided short code %s does not belong to any URL.', $shortCode) . PHP_EOL . $e + 'Provided short code {shortCode} does not belong to any URL. {e}', + ['e' => $e, 'shortCode' => $shortCode] ); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => \sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), ], self::STATUS_NOT_FOUND); } catch (Exception\DeleteShortUrlException $e) { - $this->logger->warning('Provided data is invalid.' . PHP_EOL . $e); + $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); $messagePlaceholder = $this->translator->translate( 'It is not possible to delete URL with short code "%s" because it has reached more than "%s" visits.' ); diff --git a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php index 0c1e243a..cbdb8a21 100644 --- a/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/EditShortUrlAction.php @@ -60,13 +60,13 @@ class EditShortUrlAction extends AbstractRestAction ); return new EmptyResponse(); } catch (Exception\InvalidShortCodeException $e) { - $this->logger->warning('Provided data is invalid.' . PHP_EOL . $e); + $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => \sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), ], self::STATUS_NOT_FOUND); } catch (Exception\ValidationException $e) { - $this->logger->warning('Provided data is invalid.' . PHP_EOL . $e); + $this->logger->warning('Provided data is invalid. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => $this->translator->translate('Provided data is invalid.'), diff --git a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php index 5e19f866..cf28407a 100644 --- a/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php +++ b/module/Rest/src/Action/ShortUrl/ListShortUrlsAction.php @@ -60,7 +60,7 @@ class ListShortUrlsAction extends AbstractRestAction $this->domainConfig ))]); } catch (\Exception $e) { - $this->logger->error('Unexpected error while listing short URLs.' . PHP_EOL . $e); + $this->logger->error('Unexpected error while listing short URLs. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, 'message' => $this->translator->translate('Unexpected error occurred'), diff --git a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php index 8afb55f3..3052e662 100644 --- a/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php +++ b/module/Rest/src/Action/ShortUrl/ResolveShortUrlAction.php @@ -59,7 +59,7 @@ class ResolveShortUrlAction extends AbstractRestAction $url = $this->urlShortener->shortCodeToUrl($shortCode); return new JsonResponse($transformer->transform($url)); } catch (InvalidShortCodeException $e) { - $this->logger->warning('Provided short code with invalid format.' . PHP_EOL . $e); + $this->logger->warning('Provided short code with invalid format. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => \sprintf( @@ -68,13 +68,13 @@ class ResolveShortUrlAction extends AbstractRestAction ), ], self::STATUS_BAD_REQUEST); } catch (EntityDoesNotExistException $e) { - $this->logger->warning('Provided short code couldn\'t be found.' . PHP_EOL . $e); + $this->logger->warning('Provided short code couldn\'t be found. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::INVALID_ARGUMENT_ERROR, 'message' => \sprintf($this->translator->translate('No URL found for short code "%s"'), $shortCode), ], self::STATUS_NOT_FOUND); } catch (\Exception $e) { - $this->logger->error('Unexpected error while resolving the URL behind a short code.' . PHP_EOL . $e); + $this->logger->error('Unexpected error while resolving the URL behind a short code. {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, 'message' => $this->translator->translate('Unexpected error occurred'), diff --git a/module/Rest/src/Action/Visit/GetVisitsAction.php b/module/Rest/src/Action/Visit/GetVisitsAction.php index 8f320907..67ff5fa1 100644 --- a/module/Rest/src/Action/Visit/GetVisitsAction.php +++ b/module/Rest/src/Action/Visit/GetVisitsAction.php @@ -59,7 +59,7 @@ class GetVisitsAction extends AbstractRestAction ], ]); } catch (InvalidArgumentException $e) { - $this->logger->warning('Provided nonexistent short code' . PHP_EOL . $e); + $this->logger->warning('Provided nonexistent short code {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::getRestErrorCodeFromException($e), 'message' => sprintf( @@ -68,7 +68,7 @@ class GetVisitsAction extends AbstractRestAction ), ], self::STATUS_NOT_FOUND); } catch (\Exception $e) { - $this->logger->error('Unexpected error while parsing short code' . PHP_EOL . $e); + $this->logger->error('Unexpected error while parsing short code {e}', ['e' => $e]); return new JsonResponse([ 'error' => RestUtils::UNKNOWN_ERROR, 'message' => $this->translator->translate('Unexpected error occurred'), diff --git a/module/Rest/src/Middleware/AuthenticationMiddleware.php b/module/Rest/src/Middleware/AuthenticationMiddleware.php index bb6f842f..9a9cdb10 100644 --- a/module/Rest/src/Middleware/AuthenticationMiddleware.php +++ b/module/Rest/src/Middleware/AuthenticationMiddleware.php @@ -80,7 +80,7 @@ class AuthenticationMiddleware implements MiddlewareInterface, StatusCodeInterfa try { $plugin = $this->requestToAuthPlugin->fromRequest($request); } catch (ContainerExceptionInterface | NoAuthenticationException $e) { - $this->logger->warning('Invalid or no authentication provided.' . PHP_EOL . $e); + $this->logger->warning('Invalid or no authentication provided. {e}', ['e' => $e]); return $this->createErrorResponse(sprintf($this->translator->translate( 'Expected one of the following authentication headers, but none were provided, ["%s"]' ), implode('", "', RequestToHttpAuthPlugin::SUPPORTED_AUTH_HEADERS))); @@ -91,7 +91,7 @@ class AuthenticationMiddleware implements MiddlewareInterface, StatusCodeInterfa $response = $handler->handle($request); return $plugin->update($request, $response); } catch (VerifyAuthenticationException $e) { - $this->logger->warning('Authentication verification failed.' . PHP_EOL . $e); + $this->logger->warning('Authentication verification failed. {e}', ['e' => $e]); return $this->createErrorResponse($e->getPublicMessage(), $e->getErrorCode()); } }