Skip to content

Commit d8777a7

Browse files
[Bridge\Monolog][FrameworkBundle] Add & wire a DebugProcessor
1 parent 017d814 commit d8777a7

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
13+
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
class AddDebugLogProcessorPass implements CompilerPassInterface
19+
{
20+
public function process(ContainerBuilder $container)
21+
{
22+
if (!$container->hasDefinition('profiler')) {
23+
return;
24+
}
25+
if (!$container->hasDefinition('monolog.logger_prototype')) {
26+
return;
27+
}
28+
if (!$container->hasDefinition('debug.log_processor')) {
29+
return;
30+
}
31+
32+
$definition = $container->getDefinition('monolog.logger_prototype');
33+
$definition->addMethodCall('pushProcessor', array(new Reference('debug.log_processor')));
34+
}
35+
}

DependencyInjection/FrameworkExtension.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection;
1313

1414
use Doctrine\Common\Annotations\Reader;
15+
use Symfony\Bridge\Monolog\Processor\DebugProcessor;
1516
use Symfony\Component\Cache\Adapter\AdapterInterface;
1617
use Symfony\Component\DependencyInjection\ContainerBuilder;
1718
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -468,6 +469,12 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
468469

469470
$definition->replaceArgument(4, $debug);
470471
$definition->replaceArgument(6, $debug);
472+
473+
if ($debug && class_exists(DebugProcessor::class)) {
474+
$definition = new Definition(DebugProcessor::class);
475+
$definition->setPublic(false);
476+
$container->setDefinition('debug.log_processor', $definition);
477+
}
471478
}
472479

473480
/**

FrameworkBundle.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle;
1313

1414
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConstraintValidatorsPass;
15+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
1516
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddValidatorInitializersPass;
1617
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass;
1718
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolPass;
@@ -95,6 +96,7 @@ public function build(ContainerBuilder $container)
9596
$container->addCompilerPass(new CachePoolClearerPass(), PassConfig::TYPE_AFTER_REMOVING);
9697

9798
if ($container->getParameter('kernel.debug')) {
99+
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -1);
98100
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
99101
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
100102
$container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);

0 commit comments

Comments
 (0)