Skip to content

Commit 8b5330e

Browse files
[HttpKernel][MonologBridge][FrameworkBundle] Revisit wiring of debug loggers
1 parent 1352708 commit 8b5330e

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ CHANGELOG
1010
* Add `DomCrawlerAssertionsTrait::assertAnySelectorTextContains(string $selector, string $text)`
1111
* Add `DomCrawlerAssertionsTrait::assertAnySelectorTextSame(string $selector, string $text)`
1212
* Add `DomCrawlerAssertionsTrait::assertAnySelectorTextNotContains(string $selector, string $text)`
13+
* Deprecate `EnableLoggerDebugModePass`, use argument `$debug` of HttpKernel's `Logger` instead
14+
* Deprecate `AddDebugLogProcessorPass::configureLogger()`, use HttpKernel's `DebugLoggerConfigurator` instead
1315

1416
6.3
1517
---

DependencyInjection/Compiler/AddDebugLogProcessorPass.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,19 @@ public function process(ContainerBuilder $container)
3232
return;
3333
}
3434

35-
$definition = $container->getDefinition('monolog.logger_prototype');
36-
$definition->setConfigurator([__CLASS__, 'configureLogger']);
37-
$definition->addMethodCall('pushProcessor', [new Reference('debug.log_processor')]);
35+
$container->getDefinition('monolog.logger_prototype')
36+
->setConfigurator([new Reference('debug.debug_logger_configurator'), 'pushDebugLogger']);
3837
}
3938

4039
/**
40+
* @deprecated since Symfony 6.4, use HttpKernel's DebugLoggerConfigurator instead
41+
*
4142
* @return void
4243
*/
4344
public static function configureLogger(mixed $logger)
4445
{
46+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s()" method is deprecated, use HttpKernel\'s DebugLoggerConfigurator instead.', __METHOD__);
47+
4548
if (\is_object($logger) && method_exists($logger, 'removeDebugLogger') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
4649
$logger->removeDebugLogger();
4750
}

DependencyInjection/Compiler/EnableLoggerDebugModePass.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use argument $debug of HttpKernel\'s Logger instead.', EnableLoggerDebugModePass::class);
15+
1416
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1517
use Symfony\Component\DependencyInjection\ContainerBuilder;
1618
use Symfony\Component\HttpKernel\Log\Logger;
1719

20+
/**
21+
* @deprecated since Symfony 6.4, use argument $debug of HttpKernel's Logger instead
22+
*/
1823
final class EnableLoggerDebugModePass implements CompilerPassInterface
1924
{
2025
public function process(ContainerBuilder $container): void
@@ -32,7 +37,7 @@ public function process(ContainerBuilder $container): void
3237

3338
public static function configureLogger(Logger $logger): void
3439
{
35-
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && method_exists($logger, 'enableDebug')) {
40+
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
3641
$logger->enableDebug();
3742
}
3843
}

DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
use Symfony\Component\HttpKernel\Controller\ValueResolverInterface;
102102
use Symfony\Component\HttpKernel\DataCollector\DataCollectorInterface;
103103
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
104+
use Symfony\Component\HttpKernel\Log\DebugLoggerConfigurator;
104105
use Symfony\Component\Lock\LockFactory;
105106
use Symfony\Component\Lock\LockInterface;
106107
use Symfony\Component\Lock\PersistingStoreInterface;
@@ -1171,7 +1172,11 @@ private function registerDebugConfiguration(array $config, ContainerBuilder $con
11711172
$definition = new Definition(DebugProcessor::class);
11721173
$definition->setPublic(false);
11731174
$definition->addArgument(new Reference('request_stack'));
1175+
$definition->addTag('kernel.reset', ['method' => 'reset']);
11741176
$container->setDefinition('debug.log_processor', $definition);
1177+
1178+
$container->register('debug.debug_logger_configurator', DebugLoggerConfigurator::class)
1179+
->setArguments([new Reference('debug.log_processor')]);
11751180
}
11761181
}
11771182

FrameworkBundle.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
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;
2120
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
2221
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
2322
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass;
@@ -183,7 +182,6 @@ public function build(ContainerBuilder $container)
183182
$container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass());
184183

185184
if ($container->getParameter('kernel.debug')) {
186-
$container->addCompilerPass(new EnableLoggerDebugModePass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -33);
187185
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2);
188186
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
189187
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255);

0 commit comments

Comments
 (0)