mirror of
https://github.com/Seldaek/monolog.git
synced 2025-10-21 08:36:33 +02:00
Enable JSON encode pretty print (#1236)
This commit is contained in:
committed by
Jordi Boggiano
parent
204744df2e
commit
daed05c3e5
@@ -11,9 +11,9 @@
|
||||
|
||||
namespace Monolog\Formatter;
|
||||
|
||||
use Throwable;
|
||||
use Monolog\DateTimeImmutable;
|
||||
use Monolog\Utils;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* Normalizes incoming records to remove objects/resources so it's easier to dump to various targets
|
||||
@@ -28,6 +28,8 @@ class NormalizerFormatter implements FormatterInterface
|
||||
protected $maxNormalizeDepth = 9;
|
||||
protected $maxNormalizeItemCount = 1000;
|
||||
|
||||
private $jsonEncodeOptions = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION;
|
||||
|
||||
/**
|
||||
* @param ?string $dateFormat The format of the timestamp: one supported by DateTime::format
|
||||
*/
|
||||
@@ -89,6 +91,20 @@ class NormalizerFormatter implements FormatterInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables `json_encode` pretty print.
|
||||
*/
|
||||
public function setJsonPrettyPrint(bool $enable): self
|
||||
{
|
||||
if ($enable) {
|
||||
$this->jsonEncodeOptions |= JSON_PRETTY_PRINT;
|
||||
} else {
|
||||
$this->jsonEncodeOptions ^= JSON_PRETTY_PRINT;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $data
|
||||
* @return int|bool|string|null|array
|
||||
@@ -247,7 +263,7 @@ class NormalizerFormatter implements FormatterInterface
|
||||
*/
|
||||
private function jsonEncode($data)
|
||||
{
|
||||
return json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION);
|
||||
return json_encode($data, $this->jsonEncodeOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user