Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[FrameworkBundle] Split loggers debug compiler pass #48041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[FrameworkBundle] Split loggers debug compiler pass
  • Loading branch information
MatTheCat authored and nicolas-grekas committed Nov 10, 2022
commit 926f3deba682469ca4f4e67b7cd784dad230f4c1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Log\Logger;

class AddDebugLogProcessorPass implements CompilerPassInterface
{
Expand All @@ -23,38 +22,22 @@ public function process(ContainerBuilder $container)
if (!$container->hasDefinition('profiler')) {
return;
}

if ($container->hasDefinition('monolog.logger_prototype') && $container->hasDefinition('debug.log_processor')) {
$container->getDefinition('monolog.logger_prototype')
->setConfigurator([__CLASS__, 'configureMonologLogger'])
->addMethodCall('pushProcessor', [new Reference('debug.log_processor')])
;

if (!$container->hasDefinition('monolog.logger_prototype')) {
return;
}

if (!$container->hasDefinition('logger')) {
if (!$container->hasDefinition('debug.log_processor')) {
return;
}

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

if (Logger::class === $loggerDefinition->getClass()) {
$loggerDefinition->setConfigurator([__CLASS__, 'configureHttpKernelLogger']);
}
$definition = $container->getDefinition('monolog.logger_prototype');
$definition->setConfigurator([__CLASS__, 'configureLogger']);
$definition->addMethodCall('pushProcessor', [new Reference('debug.log_processor')]);
}

public static function configureMonologLogger(mixed $logger)
public static function configureLogger(mixed $logger)
{
if (\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && \is_object($logger) && method_exists($logger, 'removeDebugLogger')) {
if (\is_object($logger) && method_exists($logger, 'removeDebugLogger') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) {
$logger->removeDebugLogger();
}
}

public static function configureHttpKernelLogger(Logger $logger)
{
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && method_exists($logger, 'enableDebug')) {
$logger->enableDebug();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Log\Logger;

final class EnableLoggerDebugModePass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('profiler') || !$container->hasDefinition('logger')) {
return;
}

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

if (Logger::class === $loggerDefinition->getClass()) {
$loggerDefinition->setConfigurator([__CLASS__, 'configureLogger']);
}
}

public static function configureLogger(Logger $logger): void
{
if (!\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true) && method_exists($logger, 'enableDebug')) {
$logger->enableDebug();
}
}
}
2 changes: 2 additions & 0 deletions 2 src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AssetsContextPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\EnableLoggerDebugModePass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass;
Expand Down Expand Up @@ -165,6 +166,7 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new RemoveUnusedSessionMarshallingHandlerPass());

if ($container->getParameter('kernel.debug')) {
$container->addCompilerPass(new EnableLoggerDebugModePass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, -33);
$container->addCompilerPass(new AddDebugLogProcessorPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 2);
$container->addCompilerPass(new UnusedTagsPass(), PassConfig::TYPE_AFTER_REMOVING);
$container->addCompilerPass(new ContainerBuilderDebugDumpPass(), PassConfig::TYPE_BEFORE_REMOVING, -255);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.