Skip to content

Commit 02c05a1

Browse files
committed
Better error reporting, make sure the "app" channel is also present
1 parent 3a6f772 commit 02c05a1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

DependencyInjection/Compiler/LoggerChannelPass.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1717
use Symfony\Component\DependencyInjection\DefinitionDecorator;
18+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1819

1920
/**
2021
* Replaces the default logger by another one with its own channel for tagged services.
@@ -23,7 +24,7 @@
2324
*/
2425
class LoggerChannelPass implements CompilerPassInterface
2526
{
26-
protected $channels = array();
27+
protected $channels = array('app');
2728

2829
public function process(ContainerBuilder $container)
2930
{
@@ -50,7 +51,12 @@ public function process(ContainerBuilder $container)
5051

5152
foreach ($handlersToChannels as $handler => $channels) {
5253
foreach ($this->processChannels($channels) as $channel) {
53-
$logger = $container->getDefinition('monolog.logger.'.$channel);
54+
try {
55+
$logger = $container->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel);
56+
} catch (InvalidArgumentException $e) {
57+
$msg = 'Monolog configuration error: The logging channel "'.$channel.'" assigned to the "'.substr($handler, 16).'" handler does not exist.';
58+
throw new \InvalidArgumentException($msg, 0, $e);
59+
}
5460
$logger->addMethodCall('pushHandler', array(new Reference($handler)));
5561
}
5662
}

0 commit comments

Comments
 (0)