From ffaff38dffd486d6ef93f76bb5a9a1142dc9d827 Mon Sep 17 00:00:00 2001 From: hectorhammett Date: Tue, 10 Dec 2024 22:29:59 +0000 Subject: [PATCH] Remove the INFO level log --- src/Logging/LoggingTrait.php | 36 +------------------- tests/HttpHandler/Guzzle7HttpHandlerTest.php | 2 -- tests/Logging/LoggingTraitTest.php | 12 +------ 3 files changed, 2 insertions(+), 48 deletions(-) diff --git a/src/Logging/LoggingTrait.php b/src/Logging/LoggingTrait.php index f42dd8daa..97c51368a 100644 --- a/src/Logging/LoggingTrait.php +++ b/src/Logging/LoggingTrait.php @@ -67,16 +67,13 @@ private function logRequest(RpcLogEvent $event): void */ private function logResponse(RpcLogEvent $event): void { - if (!is_null($event->status)) { - $this->logStatus($event); - } - $debugEvent = [ 'timestamp' => $event->timestamp, 'severity' => strtoupper(LogLevel::DEBUG), 'processId' => $event->processId ?? null, 'requestId' => $event->requestId ?? null, 'jsonPayload' => [ + 'response.status' => $event->status, 'response.headers' => $event->headers, 'response.payload' => $this->truncatePayload($event->payload), 'latencyMillis' => $event->latency, @@ -98,37 +95,6 @@ private function logResponse(RpcLogEvent $event): void } } - /** - * @param RpcLogEvent $event - */ - private function logStatus(RpcLogEvent $event): void - { - $infoEvent = [ - 'timestamp' => $event->timestamp, - 'severity' => strtoupper(LogLevel::INFO), - 'processId' => $event->processId, - 'requestId' => $event->requestId ?? null, - 'jsonPayload' => [ - 'response.status' => $event->status - ] - ]; - - $infoEvent = array_filter($infoEvent, fn ($value) => !is_null($value)); - $infoEvent['jsonPayload'] = array_filter( - $infoEvent['jsonPayload'], - fn ($value) => !is_null($value) - ); - - $stringifiedEvent = json_encode($infoEvent, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - - // There was an error stringifying the event, return to not break execution - if ($stringifiedEvent === false) { - return; - } - - $this->logger->info($stringifiedEvent); - } - /** * @param array $headers * @return null|array diff --git a/tests/HttpHandler/Guzzle7HttpHandlerTest.php b/tests/HttpHandler/Guzzle7HttpHandlerTest.php index fe77a49b0..97cb8688d 100644 --- a/tests/HttpHandler/Guzzle7HttpHandlerTest.php +++ b/tests/HttpHandler/Guzzle7HttpHandlerTest.php @@ -49,8 +49,6 @@ public function testLoggerGetsCalledIfLoggerIsPassed() $mockLogger = $this->prophesize(StdOutLogger::class); $mockLogger->debug(Argument::cetera()) ->shouldBeCalledTimes(2); - $mockLogger->info(Argument::cetera()) - ->shouldBeCalledTimes(1); $this->client->sendAsync(Argument::cetera()) ->willReturn($requestPromise); diff --git a/tests/Logging/LoggingTraitTest.php b/tests/Logging/LoggingTraitTest.php index 620e21489..edc85b5bd 100644 --- a/tests/Logging/LoggingTraitTest.php +++ b/tests/Logging/LoggingTraitTest.php @@ -68,20 +68,10 @@ public function testLogResponse() $buffer = $this->getActualOutput(); - $buffer = str_replace("\n", '', $buffer); - - // The LogResponse method logs two events, one for info and one for debug. - [$infoEvent, $debugEvent] = explode('}{', $buffer); - $infoEvent .= '}'; - $debugEvent = '{' . $debugEvent; - - $parsedDebugEvent = json_decode($debugEvent, true); + $parsedDebugEvent = json_decode($buffer, true); $this->assertEquals($event->processId, $parsedDebugEvent['processId']); $this->assertEquals($event->requestId, $parsedDebugEvent['requestId']); $this->assertEquals($event->headers, $parsedDebugEvent['jsonPayload']['response.headers']); - - $parsedInfoEvent = json_decode($infoEvent, true); - $this->assertEquals($event->status, $parsedInfoEvent['jsonPayload']['response.status']); } private function getNewLogEvent(): RpcLogEvent