Skip to content

Commit 9205166

Browse files
committed
feature #21396 [DI] Enhance logging in compiler passes (nicolas-grekas)
This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Enhance logging in compiler passes | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - We should log more in compiler passes - and this should be better integrated in usual log reports. For logging more, let's drop LoggingFormatter and add a simple "log" method on ContainerBuilder. For better integration, let's throw silenced notices - they can be caught by our Debug handler. Commits ------- fb200a0d2f [DI] Enhance logging in compiler passes
2 parents f6b7722 + df13f40 commit 9205166

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class UnusedTagsPass implements CompilerPassInterface
5353

5454
public function process(ContainerBuilder $container)
5555
{
56-
$compiler = $container->getCompiler();
57-
$formatter = $compiler->getLoggingFormatter();
5856
$tags = array_unique(array_merge($container->findTags(), $this->whitelist));
5957

6058
foreach ($container->findUnusedTags() as $tag) {
@@ -81,7 +79,7 @@ public function process(ContainerBuilder $container)
8179
$message .= sprintf(' Did you mean "%s"?', implode('", "', $candidates));
8280
}
8381

84-
$compiler->addLogMessage($formatter->format($this, $message));
82+
$container->log($this, $message);
8583
}
8684
}
8785
}

FrameworkBundle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public function build(ContainerBuilder $container)
106106
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
107107
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
108108
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
109-
$container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING);
109+
$container->addCompilerPass(new CompilerDebugDumpPass(), PassConfig::TYPE_AFTER_REMOVING, -32);
110110
$container->addCompilerPass(new ConfigCachePass());
111111
$container->addCompilerPass(new CacheCollectorPass());
112112
}

Tests/DependencyInjection/Compiler/UnusedTagsPassTest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,10 @@ public function testProcess()
1919
{
2020
$pass = new UnusedTagsPass();
2121

22-
$formatter = $this->getMockBuilder('Symfony\Component\DependencyInjection\Compiler\LoggingFormatter')->getMock();
23-
$formatter
24-
->expects($this->at(0))
25-
->method('format')
26-
->with($pass, 'Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?')
27-
;
28-
29-
$compiler = $this->getMockBuilder('Symfony\Component\DependencyInjection\Compiler\Compiler')->getMock();
30-
$compiler->expects($this->once())->method('getLoggingFormatter')->will($this->returnValue($formatter));
31-
32-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'getCompiler', 'findUnusedTags', 'findTags'))->getMock();
33-
$container->expects($this->once())->method('getCompiler')->will($this->returnValue($compiler));
22+
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('findTaggedServiceIds', 'findUnusedTags', 'findTags', 'log'))->getMock();
23+
$container->expects($this->once())
24+
->method('log')
25+
->with($pass, 'Tag "kenrel.event_subscriber" was defined on service(s) "foo", "bar", but was never used. Did you mean "kernel.event_subscriber"?');
3426
$container->expects($this->once())
3527
->method('findTags')
3628
->will($this->returnValue(array('kenrel.event_subscriber')));

0 commit comments

Comments
 (0)