Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
update JsonFormatterFactory (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
mimmi20 committed Mar 15, 2022
1 parent c99f139 commit 4489079
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"phpstan/phpstan": "^1.4.10",
"phpstan/phpstan-deprecation-rules": "^1.0.0",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpunit/phpunit": "^9.5.18",
"phpunit/phpunit": "^9.5.19",
"predis/predis": "^1.1.10",
"rollbar/rollbar": "^v2.1.0 || ^v3.1.1",
"ruflin/elastica": "^7.1.4",
Expand Down
14 changes: 8 additions & 6 deletions src/Formatter/JsonFormatterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Monolog\Formatter\JsonFormatter;
use Monolog\Formatter\NormalizerFormatter;

use function array_key_exists;
use function is_array;
Expand All @@ -39,6 +40,8 @@ public function __invoke(ContainerInterface $container, $requestedName, ?array $
$maxNormalizeDepth = NormalizerFormatterFactory::DEFAULT_NORMALIZER_DEPTH;
$maxNormalizeItemCount = NormalizerFormatterFactory::DEFAULT_NORMALIZER_ITEM_COUNT;
$prettyPrint = false;
$includeStacktraces = false;
$dateFormat = NormalizerFormatter::SIMPLE_DATE;

if (is_array($options)) {
if (array_key_exists('batchMode', $options)) {
Expand All @@ -64,20 +67,19 @@ public function __invoke(ContainerInterface $container, $requestedName, ?array $
if (array_key_exists('prettyPrint', $options)) {
$prettyPrint = $options['prettyPrint'];
}
}

$formatter = new JsonFormatter($batchMode, $appendNewline, $ignoreEmptyContextAndExtra);

if (is_array($options)) {
if (array_key_exists('includeStacktraces', $options)) {
$formatter->includeStacktraces($options['includeStacktraces']);
$includeStacktraces = $options['includeStacktraces'];
}

if (array_key_exists('dateFormat', $options)) {
$formatter->setDateFormat($options['dateFormat']);
$dateFormat = $options['dateFormat'];
}
}

$formatter = new JsonFormatter($batchMode, $appendNewline, $ignoreEmptyContextAndExtra, $includeStacktraces);

$formatter->setDateFormat($dateFormat);
$formatter->setMaxNormalizeDepth($maxNormalizeDepth);
$formatter->setMaxNormalizeItemCount($maxNormalizeItemCount);
$formatter->setJsonPrettyPrint($prettyPrint);
Expand Down

0 comments on commit 4489079

Please sign in to comment.