Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 926f3de

Browse filesBrowse files
MatTheCatnicolas-grekas
authored andcommitted
[FrameworkBundle] Split loggers debug compiler pass
1 parent 860d86a commit 926f3de
Copy full SHA for 926f3de

File tree

3 files changed

+48
-24
lines changed
Filter options

3 files changed

+48
-24
lines changed

‎src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php
+7-24Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Reference;
17-
use Symfony\Component\HttpKernel\Log\Logger;
1817

1918
class AddDebugLogProcessorPass implements CompilerPassInterface
2019
{
@@ -23,38 +22,22 @@ public function process(ContainerBuilder $container)
2322
if (!$container->hasDefinition('profiler')) {
2423
return;
2524
}
26-
27-
if ($container->hasDefinition('monolog.logger_prototype') && $container->hasDefinition('debug.log_processor')) {
28-
$container->getDefinition('monolog.logger_prototype')
29-
->setConfigurator([__CLASS__, 'configureMonologLogger'])
30-
->addMethodCall('pushProcessor', [new Reference('debug.log_processor')])
31-
;
32-
25+
if (!$container->hasDefinition('monolog.logger_prototype')) {
3326
return;
3427
}
35-
36-
if (!$container->hasDefinition('logger')) {
28+
if (!$container->hasDefinition('debug.log_processor')) {
3729
return;
3830
}
3931

40-
$loggerDefinition = $container->getDefinition('logger');
41-
42-
if (Logger::class === $loggerDefinition->getClass()) {
43-
$loggerDefinition->setConfigurator([__CLASS__, 'configureHttpKernelLogger']);
44-
}
32+
$definition = $container->getDefinition('monolog.logger_prototype');
33+
$definition->setConfigurator([__CLASS__, 'configureLogger']);
34+
$definition->addMethodCall('pushProcessor', [new Reference('debug.log_processor')]);
4535
}
4636

47-
public static function configureMonologLogger(mixed $logger)
37+
public static function configureLogger(mixed $logger)
4838
{
49-
if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && \is_object($logger) && method_exists($logger, 'removeDebugLogger')) {
39+
if (\is_object($logger) && method_exists($logger, 'removeDebugLogger') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
5040
$logger->removeDebugLogger();
5141
}
5242
}
53-
54-
public static function configureHttpKernelLogger(Logger $logger)
55-
{
56-
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && method_exists($logger, 'enableDebug')) {
57-
$logger->enableDebug();
58-
}
59-
}
6043
}
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\HttpKernel\Log\Logger;
17+
18+
final class EnableLoggerDebugModePass implements CompilerPassInterface
19+
{
20+
public function process(ContainerBuilder $container)
21+
{
22+
if (!$container->hasDefinition('profiler') || !$container->hasDefinition('logger')) {
23+
return;
24+
}
25+
26+
$loggerDefinition = $container->getDefinition('logger');
27+
28+
if (Logger::class === $loggerDefinition->getClass()) {
29+
$loggerDefinition->setConfigurator([__CLASS__, 'configureLogger']);
30+
}
31+
}
32+
33+
public static function configureLogger(Logger $logger): void
34+
{
35+
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && method_exists($logger, 'enableDebug')) {
36+
$logger->enableDebug();
37+
}
38+
}
39+
}

‎src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AssetsContextPass;
1818
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
1919
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
20+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\EnableLoggerDebugModePass;
2021
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
2122
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
2223
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass;
@@ -165,6 +166,7 @@ public function build(ContainerBuilder $container)
165166
$container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass());
166167

167168
if ($container->getParameter('kernel.debug')) {
169+
$container->addCompilerPass(new EnableLoggerDebugModePass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -33);
168170
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2);
169171
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
170172
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.