Skip to content

Commit 3f17d62

Browse files
committed
Split loggers debug compiler pass
1 parent c1311c1 commit 3f17d62

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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\DependencyInjection\Reference;
17+
18+
class AddMonologDebugLogProcessorPass 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+
$container->getDefinition('monolog.logger_prototype')
33+
->setConfigurator([__CLASS__, 'configure'])
34+
->addMethodCall('pushProcessor', [new Reference('debug.log_processor')])
35+
;
36+
}
37+
38+
public static function configure(mixed $logger)
39+
{
40+
if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && \is_object($logger) && method_exists($logger, 'removeDebugLogger')) {
41+
$logger->removeDebugLogger();
42+
}
43+
}
44+
}

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php renamed to src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/EnableLoggerDebugModePass.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,27 @@
1313

1414
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Reference;
1716
use Symfony\Component\HttpKernel\Log\Logger;
1817

19-
class AddDebugLogProcessorPass implements CompilerPassInterface
18+
class EnableLoggerDebugModePass implements CompilerPassInterface
2019
{
2120
public function process(ContainerBuilder $container)
2221
{
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-
33-
return;
34-
}
35-
3625
if (!$container->hasDefinition('logger')) {
3726
return;
3827
}
3928

4029
$loggerDefinition = $container->getDefinition('logger');
4130

4231
if (Logger::class === $loggerDefinition->getClass()) {
43-
$loggerDefinition->setConfigurator([__CLASS__, 'configureHttpKernelLogger']);
44-
}
45-
}
46-
47-
public static function configureMonologLogger(mixed $logger)
48-
{
49-
if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && \is_object($logger) && method_exists($logger, 'removeDebugLogger')) {
50-
$logger->removeDebugLogger();
32+
$loggerDefinition->setConfigurator([__CLASS__, 'configure']);
5133
}
5234
}
5335

54-
public static function configureHttpKernelLogger(Logger $logger)
36+
public static function configure(Logger $logger)
5537
{
5638
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && method_exists($logger, 'enableDebug')) {
5739
$logger->enableDebug();

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

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

1414
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
15-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
1615
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
16+
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddMonologDebugLogProcessorPass;
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,7 +166,8 @@ public function build(ContainerBuilder $container)
165166
$container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass());
166167

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

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