Skip to content

Commit

Permalink
Merge pull request #68 from neighborhoods/feature/KOJO-99
Browse files Browse the repository at this point in the history
Add a log format option to pretty print JSON
  • Loading branch information
alexberryman committed May 6, 2019
2 parents 9ba59ed + e1714dd commit 4d04304
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/Process/Pool/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
8 changes: 8 additions & 0 deletions src/Process/Pool/Logger/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4d04304

Please sign in to comment.