Skip to content

Commit

Permalink
Remove the INFO level log
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Dec 10, 2024
1 parent 8d9ade7 commit ffaff38
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 48 deletions.
36 changes: 1 addition & 35 deletions src/Logging/LoggingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<mixed> $headers
* @return null|array<string, string|false>
Expand Down
2 changes: 0 additions & 2 deletions tests/HttpHandler/Guzzle7HttpHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 1 addition & 11 deletions tests/Logging/LoggingTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ffaff38

Please sign in to comment.