Skip to content

Commit 980df7a

Browse files
committed
Split loggers debug compiler pass
1 parent 860d86a commit 980df7a

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed

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

Lines changed: 7 additions & 23 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,23 @@ 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+
$container->getDefinition('monolog.logger_prototype')
33+
->setConfigurator([__CLASS__, 'configure'])
34+
->addMethodCall('pushProcessor', [new Reference('debug.log_processor')])
35+
;
4536
}
4637

47-
public static function configureMonologLogger(mixed $logger)
38+
public static function configure(mixed $logger)
4839
{
4940
if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && \is_object($logger) && method_exists($logger, 'removeDebugLogger')) {
5041
$logger->removeDebugLogger();
5142
}
5243
}
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-
}
6044
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
class EnableLoggerDebugModePass implements CompilerPassInterface
19+
{
20+
public function process(ContainerBuilder $container)
21+
{
22+
if (!$container->hasDefinition('profiler')) {
23+
return;
24+
}
25+
if (!$container->hasDefinition('logger')) {
26+
return;
27+
}
28+
29+
$loggerDefinition = $container->getDefinition('logger');
30+
31+
if (Logger::class === $loggerDefinition->getClass()) {
32+
$loggerDefinition->setConfigurator([__CLASS__, 'configure']);
33+
}
34+
}
35+
36+
public static function configure(Logger $logger)
37+
{
38+
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && method_exists($logger, 'enableDebug')) {
39+
$logger->enableDebug();
40+
}
41+
}
42+
}

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy