Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df8b364

Browse files
committed
[FrameworkBundle] Configure logger as error logger if the Monolog Bundle is not registered
1 parent da14597 commit df8b364

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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 ErrorLoggerCompilerPass implements CompilerPassInterface
19+
{
20+
public function process(ContainerBuilder $container)
21+
{
22+
if (!$container->hasDefinition('debug.debug_handlers_listener')) {
23+
return;
24+
}
25+
26+
$definition = $container->getDefinition('debug.debug_handlers_listener');
27+
if ($container->hasDefinition('monolog.logger.php')) {
28+
$definition->replaceArgument(1, new Reference('monolog.logger.php'));
29+
}
30+
if ($container->hasDefinition('monolog.logger.deprecation')) {
31+
$definition->replaceArgument(6, new Reference('monolog.logger.deprecation'));
32+
}
33+
}
34+
}

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 3 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\ErrorLoggerCompilerPass;
2021
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
2122
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
2223
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass;
@@ -160,6 +161,8 @@ public function build(ContainerBuilder $container)
160161
$container->addCompilerPass(new RegisterReverseContainerPass(false), PassConfig::TYPE_AFTER_REMOVING);
161162
$container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass());
162163
$container->addCompilerPass(new SessionPass());
164+
// must be registered after MonologBundle's LoggerChannelPass
165+
$container->addCompilerPass(new ErrorLoggerCompilerPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
163166

164167
if ($container->getParameter('kernel.debug')) {
165168
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2);

src/Symfony/Bundle/FrameworkBundle/Resources/config/debug_prod.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
->set('debug.debug_handlers_listener', DebugHandlersListener::class)
2222
->args([
2323
null, // Exception handler
24-
service('monolog.logger.php')->nullOnInvalid(),
24+
service('logger')->nullOnInvalid(),
2525
null, // Log levels map for enabled error levels
2626
param('debug.error_handler.throw_at'),
2727
param('kernel.debug'),
2828
param('kernel.debug'),
29-
service('monolog.logger.deprecation')->nullOnInvalid(),
29+
service('logger')->nullOnInvalid(),
3030
])
3131
->tag('kernel.event_subscriber')
3232
->tag('monolog.logger', ['channel' => 'php'])

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public function testEnabledPhpErrorsConfig()
507507
$container = $this->createContainerFromFile('php_errors_enabled');
508508

509509
$definition = $container->getDefinition('debug.debug_handlers_listener');
510-
$this->assertEquals(new Reference('monolog.logger.php', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(1));
510+
$this->assertEquals(new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(1));
511511
$this->assertNull($definition->getArgument(2));
512512
$this->assertSame(-1, $container->getParameter('debug.error_handler.throw_at'));
513513
}
@@ -527,7 +527,7 @@ public function testPhpErrorsWithLogLevel()
527527
$container = $this->createContainerFromFile('php_errors_log_level');
528528

529529
$definition = $container->getDefinition('debug.debug_handlers_listener');
530-
$this->assertEquals(new Reference('monolog.logger.php', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(1));
530+
$this->assertEquals(new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(1));
531531
$this->assertSame(8, $definition->getArgument(2));
532532
}
533533

@@ -536,7 +536,7 @@ public function testPhpErrorsWithLogLevels()
536536
$container = $this->createContainerFromFile('php_errors_log_levels');
537537

538538
$definition = $container->getDefinition('debug.debug_handlers_listener');
539-
$this->assertEquals(new Reference('monolog.logger.php', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(1));
539+
$this->assertEquals(new Reference('logger', ContainerInterface::NULL_ON_INVALID_REFERENCE), $definition->getArgument(1));
540540
$this->assertSame([
541541
\E_NOTICE => \Psr\Log\LogLevel::ERROR,
542542
\E_WARNING => \Psr\Log\LogLevel::ERROR,

0 commit comments

Comments
 (0)