Skip to content

Commit

Permalink
Init wiring up of v2 only handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
inverse committed Sep 2, 2019
1 parent fabf119 commit 30963a8
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions DependencyInjection/MonologExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\MonologBundle\DependencyInjection;

use InvalidArgumentException;
use Monolog\Logger;
use Monolog\Processor\ProcessorInterface;
use Monolog\ResettableInterface;
Expand Down Expand Up @@ -467,6 +468,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler

case 'group':
case 'whatfailuregroup':
case 'fallbackgroup':
$references = [];
foreach ($handler['members'] as $nestedHandler) {
$nestedHandlerId = $this->getHandlerId($nestedHandler);
Expand All @@ -479,7 +481,6 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
$handler['bubble'],
]);
break;

case 'syslog':
$definition->setArguments([
$handler['ident'],
Expand Down Expand Up @@ -857,7 +858,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
$nullWarning = ', if you meant to define a null handler in a yaml config, make sure you quote "null" so it does not get converted to a php null';
}

throw new \InvalidArgumentException(sprintf('Invalid handler type "%s" given for handler "%s"' . $nullWarning, $handler['type'], $name));
throw new InvalidArgumentException(sprintf('Invalid handler type "%s" given for handler "%s"' . $nullWarning, $handler['type'], $name));
}

if (!empty($handler['nested']) && true === $handler['nested']) {
Expand Down Expand Up @@ -938,8 +939,33 @@ private function getHandlerClassByType($handlerType)
'insightops' => 'Monolog\Handler\InsightOpsHandler',
];

$typeToClassMappingV2Added = [
'fallbackgroup' => 'Monolog\Handler\FallbackGroupHandler',
];

$typeToClassMappingV2Removed = [
'hipchat',
'raven',
];

if (Logger::API === 2) {
$typeToClassMapping = array_merge($typeToClassMapping, $typeToClassMappingV2Added);

foreach($typeToClassMappingV2Removed as $key) {
unset($typeToClassMapping[$key]);
}
}

if (!isset($typeToClassMapping[$handlerType])) {
throw new \InvalidArgumentException(sprintf('There is no handler class defined for handler "%s".', $handlerType));
if (array_key_exists($handlerType, $typeToClassMappingV2Added)) {
throw new InvalidArgumentException(
sprintf('"%s" was added in MonoLog 2.', $handlerType)
);
}

throw new InvalidArgumentException(
sprintf('There is no handler class defined for handler "%s".', $handlerType)
);
}

return $typeToClassMapping[$handlerType];
Expand Down

0 comments on commit 30963a8

Please sign in to comment.