Skip to content

Commit

Permalink
Merge pull request #13 from softonic/Allow-logs-for-outgoing-and-inco…
Browse files Browse the repository at this point in the history
…ming-protobuf-messages

Added exception to formatIncomingMessage
  • Loading branch information
xaviapa authored Mar 1, 2024
2 parents b7fe0b5 + 9f129e0 commit dfb2a61
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/ExternalEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public static function decorateListener(string $listenerClass): \Closure
$logMessage = self::$formatter->formatIncomingMessage(
$event,
$message[0],
$executionTimeMs
$executionTimeMs,
$exception ?? null
);

self::$logger->log($level, $logMessage->message, $logMessage->context);
Expand Down
7 changes: 4 additions & 3 deletions src/LogMessageFormatterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public function formatOutgoingMessage(
): LogMessage;

public function formatIncomingMessage(
string $routingKey,
array $message,
int $executionTimeMs
string $routingKey,
array $message,
int $executionTimeMs,
?Throwable $exception = null
): LogMessage;
}
7 changes: 5 additions & 2 deletions tests/ExternalEventsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ public function handle(FakeMessage $message)
'data' => $message->serializeToJsonString(),
'headers' => ['xRequestId' => '7b15d663-8d55-4e2f-82cc-4473576a4a17'],
],
$this->isType('int')
$this->isType('int'),
null
)
->andReturn(new LogMessage(':message:', ['context' => ':context:']));

Expand Down Expand Up @@ -411,8 +412,10 @@ public function handle(FakeMessage $message)
'client' => ':client:',
'data' => $message->serializeToJsonString(),
'headers' => ['xRequestId' => '7b15d663-8d55-4e2f-82cc-4473576a4a17'],

],
$this->isType('int')
$this->isType('int'),
$this->isInstanceOf(Exception::class)
)
->andReturn(new LogMessage(':message:', ['context' => ':context:']));

Expand Down

0 comments on commit dfb2a61

Please sign in to comment.