diff --git a/module/Core/src/EventDispatcher/LocateShortUrlVisit.php b/module/Core/src/EventDispatcher/LocateShortUrlVisit.php index 1facba39..3c40d0a1 100644 --- a/module/Core/src/EventDispatcher/LocateShortUrlVisit.php +++ b/module/Core/src/EventDispatcher/LocateShortUrlVisit.php @@ -46,7 +46,9 @@ class LocateShortUrlVisit /** @var Visit|null $visit */ $visit = $this->em->find(Visit::class, $visitId); if ($visit === null) { - $this->logger->warning(sprintf('Tried to locate visit with id "%s", but it does not exist.', $visitId)); + $this->logger->warning('Tried to locate visit with id "{visitId}", but it does not exist.', [ + 'visitId' => $visitId, + ]); return; } @@ -57,11 +59,8 @@ class LocateShortUrlVisit } catch (GeolocationDbUpdateFailedException $e) { if (! $e->olderDbExists()) { $this->logger->error( - sprintf( - 'GeoLite2 database download failed. It is not possible to locate visit with id %s. {e}', - $visitId - ), - ['e' => $e] + 'GeoLite2 database download failed. It is not possible to locate visit with id {visitId}. {e}', + ['e' => $e, 'visitId' => $visitId] ); return; } @@ -75,8 +74,8 @@ class LocateShortUrlVisit : Location::emptyInstance(); } catch (WrongIpException $e) { $this->logger->warning( - sprintf('Tried to locate visit with id "%s", but its address seems to be wrong. {e}', $visitId), - ['e' => $e] + 'Tried to locate visit with id "{visitId}", but its address seems to be wrong. {e}', + ['e' => $e, 'visitId' => $visitId] ); return; } diff --git a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php index 0b557dd8..88b7d6c0 100644 --- a/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php +++ b/module/Core/test/EventDispatcher/LocateShortUrlVisitTest.php @@ -56,7 +56,9 @@ class LocateShortUrlVisitTest extends TestCase { $event = new ShortUrlVisited('123'); $findVisit = $this->em->find(Visit::class, '123')->willReturn(null); - $logWarning = $this->logger->warning('Tried to locate visit with id "123", but it does not exist.'); + $logWarning = $this->logger->warning('Tried to locate visit with id "{visitId}", but it does not exist.', [ + 'visitId' => 123, + ]); ($this->locateVisit)($event); @@ -77,7 +79,7 @@ class LocateShortUrlVisitTest extends TestCase WrongIpException::class ); $logWarning = $this->logger->warning( - Argument::containingString('Tried to locate visit with id "123", but its address seems to be wrong.'), + Argument::containingString('Tried to locate visit with id "{visitId}", but its address seems to be wrong.'), Argument::type('array') ); @@ -142,7 +144,7 @@ class LocateShortUrlVisitTest extends TestCase } /** @test */ - public function errorWhenUpdatingGeoliteWithExistingCopyLogsWarning(): void + public function errorWhenUpdatingGeoLiteWithExistingCopyLogsWarning(): void { $e = GeolocationDbUpdateFailedException::create(true); $ipAddr = '1.2.3.0'; @@ -170,7 +172,7 @@ class LocateShortUrlVisitTest extends TestCase } /** @test */ - public function errorWhenDownloadingGeoliteCancelsLocation(): void + public function errorWhenDownloadingGeoLiteCancelsLocation(): void { $e = GeolocationDbUpdateFailedException::create(false); $ipAddr = '1.2.3.0'; @@ -184,8 +186,8 @@ class LocateShortUrlVisitTest extends TestCase $resolveIp = $this->ipLocationResolver->resolveIpLocation($ipAddr)->willReturn($location); $checkUpdateDb = $this->dbUpdater->checkDbUpdate(Argument::cetera())->willThrow($e); $logError = $this->logger->error( - 'GeoLite2 database download failed. It is not possible to locate visit with id 123. {e}', - ['e' => $e] + 'GeoLite2 database download failed. It is not possible to locate visit with id {visitId}. {e}', + ['e' => $e, 'visitId' => 123] ); ($this->locateVisit)($event);