From e1714dd3163bf4c476903a5f21a67b2bff95026b Mon Sep 17 00:00:00 2001 From: Alex Berryman Date: Fri, 3 May 2019 13:05:24 -0500 Subject: [PATCH] make json_pretty_print option controllable --- src/Process/Pool/Logger.php | 1 - src/Process/Pool/Logger/Formatter.php | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Process/Pool/Logger.php b/src/Process/Pool/Logger.php index b2c5f63b..ff152b67 100644 --- a/src/Process/Pool/Logger.php +++ b/src/Process/Pool/Logger.php @@ -57,7 +57,6 @@ public function log($level, $message, array $context = []) if (array_key_exists(self::CONTEXT_KEY_EXCEPTION, $context) && $context[self::CONTEXT_KEY_EXCEPTION] instanceof \Throwable){ - $context[self::CONTEXT_KEY_EXCEPTION_STRING] = (string)$context[self::CONTEXT_KEY_EXCEPTION]; $normalizedException = (new NormalizerFormatter())->format([$context[self::CONTEXT_KEY_EXCEPTION]]); unset($context[self::CONTEXT_KEY_EXCEPTION]); $context[self::CONTEXT_KEY_EXCEPTION] = $normalizedException[0]; diff --git a/src/Process/Pool/Logger/Formatter.php b/src/Process/Pool/Logger/Formatter.php index a92f50d0..91711587 100644 --- a/src/Process/Pool/Logger/Formatter.php +++ b/src/Process/Pool/Logger/Formatter.php @@ -17,11 +17,14 @@ class Formatter implements FormatterInterface const LOG_FORMAT_PIPES = 'pipes'; const LOG_FORMAT_JSON = 'json'; + const LOG_FORMAT_JSON_PRETTY_PRINT = 'json_pretty_print'; public function getFormattedMessage(MessageInterface $message) : string { if ($this->hasLogFormat() && $this->getLogFormat() === self::LOG_FORMAT_PIPES) { return $this->formatPipes($message); + } elseif ($this->hasLogFormat() && $this->getLogFormat() === self::LOG_FORMAT_JSON_PRETTY_PRINT) { + return $this->formatJsonPrettyPrint($message); } else { return $this->formatJson($message); } @@ -58,6 +61,11 @@ protected function formatJson(MessageInterface $message) : string return json_encode($message); } + protected function formatJsonPrettyPrint(MessageInterface $message) : string + { + return json_encode($message, JSON_PRETTY_PRINT); + } + public function setProcessPathPadding(int $processPathPadding) : FormatterInterface { $this->_create(self::PROP_PROCESS_PATH_PADDING, $processPathPadding);