Skip to content

Commit 4d5a969

Browse files
committed
The debug handler should always be added last
1 parent 02c05a1 commit 4d5a969

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

DependencyInjection/Compiler/DebugHandlerPass.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,26 @@
2424
*/
2525
class DebugHandlerPass implements CompilerPassInterface
2626
{
27+
private $channelPass;
28+
29+
public function __construct(LoggerChannelPass $channelPass)
30+
{
31+
$this->channelPass = $channelPass;
32+
}
33+
2734
public function process(ContainerBuilder $container)
2835
{
29-
if (!$container->hasDefinition('monolog.logger_prototype') || !$container->hasDefinition('profiler')) {
36+
if (!$container->hasDefinition('profiler')) {
3037
return;
3138
}
3239

3340
$debugHandler = new Definition('%monolog.handler.debug.class%', array(Logger::DEBUG, true));
3441
$container->setDefinition('monolog.handler.debug', $debugHandler);
35-
$container->getDefinition('monolog.logger_prototype')->addMethodCall('pushHandler', array(new Reference('monolog.handler.debug')));
42+
43+
foreach ($this->channelPass->getChannels() as $channel) {
44+
$container
45+
->getDefinition($channel === 'app' ? 'monolog.logger' : 'monolog.logger.'.$channel)
46+
->addMethodCall('pushHandler', array(new Reference('monolog.handler.debug')));
47+
}
3648
}
3749
}

DependencyInjection/Compiler/LoggerChannelPass.php

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ public function process(ContainerBuilder $container)
6262
}
6363
}
6464

65+
public function getChannels()
66+
{
67+
return $this->channels;
68+
}
69+
6570
protected function processChannels($configuration)
6671
{
6772
if (null === $configuration) {

MonologBundle.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function build(ContainerBuilder $container)
2828
{
2929
parent::build($container);
3030

31-
$container->addCompilerPass(new LoggerChannelPass());
32-
$container->addCompilerPass(new DebugHandlerPass());
31+
$container->addCompilerPass($channelPass = new LoggerChannelPass());
32+
$container->addCompilerPass(new DebugHandlerPass($channelPass));
3333
$container->addCompilerPass(new AddProcessorsPass());
3434
}
3535
}

0 commit comments

Comments
 (0)