Skip to content

Commit

Permalink
Convert GelfMessage into string required by createAmqpMessage (#1869)
Browse files Browse the repository at this point in the history
* Convert GelfMessage into string required by createAmqpMessage

* Convert object on write() too
  • Loading branch information
syssi committed Apr 12, 2024
1 parent 35dab43 commit 814ea50
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Monolog/Handler/AmqpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Monolog\Handler;

use Gelf\Message as GelfMessage;
use Monolog\Level;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\JsonFormatter;
Expand Down Expand Up @@ -75,6 +76,10 @@ protected function write(LogRecord $record): void
$data = $record->formatted;
$routingKey = $this->getRoutingKey($record);

if($data instanceof GelfMessage) {
$data = json_encode($data->toArray());
}

if ($this->exchange instanceof AMQPExchange) {
$attributes = [
'delivery_mode' => 2,
Expand Down Expand Up @@ -117,6 +122,10 @@ public function handleBatch(array $records): void
$record = $this->processRecord($record);
$data = $this->getFormatter()->format($record);

if($data instanceof GelfMessage) {
$data = json_encode($data->toArray());
}

$this->exchange->batch_basic_publish(
$this->createAmqpMessage($data),
$this->exchangeName,
Expand Down

0 comments on commit 814ea50

Please sign in to comment.