Skip to content

Commit

Permalink
Prevent sending associative arrays to logtail (#7)
Browse files Browse the repository at this point in the history
* Prevent sending associative arrays to logtail

* Fix CHANGELOG.md

Co-authored-by: Jindra Regal <[email protected]>
  • Loading branch information
jindraregal and Jindra Regal authored Oct 17, 2022
1 parent 81f1657 commit 15c7642
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ All notable changes to this project will be documented in this file.
* Switched to BufferHandler to send logs in batches.
* Introduced SynchronousLogtailHandler for backward compatibility.

## [0.1.5] - 2022-10-13

* Prevent sending associative array in batch mode.
* Increased limit of logs that can be formatted and sent in batches.



8 changes: 5 additions & 3 deletions src/Monolog/LogtailFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
*/
class LogtailFormatter extends \Monolog\Formatter\JsonFormatter {

public function __construct($batchMode = self::BATCH_MODE_JSON, $appendNewline = false) {
parent::__construct($batchMode, $appendNewline);
public function __construct() {
parent::__construct(self::BATCH_MODE_JSON, false);
$this->setMaxNormalizeItemCount(PHP_INT_MAX);
}

public function format(array $record): string {
Expand All @@ -26,7 +27,8 @@ public function format(array $record): string {

public function formatBatch(array $records): string
{
return parent::formatBatch(array_map('self::formatRecord', $records));
$normalized = array_values($this->normalize(array_map('self::formatRecord', $records)));
return $this->toJson($normalized, true);
}

protected static function formatRecord(array $record): array
Expand Down

0 comments on commit 15c7642

Please sign in to comment.