diff --git a/UPGRADE-7.0.md b/UPGRADE-7.0.md index 34653b6f4434e..0e4d17f35cceb 100644 --- a/UPGRADE-7.0.md +++ b/UPGRADE-7.0.md @@ -199,6 +199,8 @@ FrameworkBundle ``` * Remove the integration of Doctrine annotations, use native attributes instead + * Remove `EnableLoggerDebugModePass`, use argument `$debug` of HttpKernel's `Logger` instead + * Remove `AddDebugLogProcessorPass::configureLogger()`, use HttpKernel's `DebugLoggerConfigurator` instead HttpFoundation -------------- @@ -264,6 +266,7 @@ MonologBridge ------------- * Drop support for monolog < 3.0 + * Remove class `Logger`, use HttpKernel's `DebugLoggerConfigurator` instead PropertyAccess -------------- diff --git a/src/Symfony/Bridge/Monolog/CHANGELOG.md b/src/Symfony/Bridge/Monolog/CHANGELOG.md index aa66f5b3a2d21..9bce3eacd7cc9 100644 --- a/src/Symfony/Bridge/Monolog/CHANGELOG.md +++ b/src/Symfony/Bridge/Monolog/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG --- * Drop support for monolog < 3.0 + * Remove class `Logger`, use HttpKernel's `DebugLoggerConfigurator` instead 6.4 --- diff --git a/src/Symfony/Bridge/Monolog/Logger.php b/src/Symfony/Bridge/Monolog/Logger.php deleted file mode 100644 index 3542525e05814..0000000000000 --- a/src/Symfony/Bridge/Monolog/Logger.php +++ /dev/null @@ -1,95 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bridge\Monolog; - -trigger_deprecation('symfony/monolog-bridge', '6.4', 'The "%s" class is deprecated, use HttpKernel\'s DebugLoggerConfigurator instead.', Logger::class); - -use Monolog\Logger as BaseLogger; -use Monolog\ResettableInterface; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; -use Symfony\Contracts\Service\ResetInterface; - -/** - * @deprecated since Symfony 6.4, use HttpKernel's DebugLoggerConfigurator instead - */ -class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface -{ - public function getLogs(Request $request = null): array - { - if ($logger = $this->getDebugLogger()) { - return $logger->getLogs($request); - } - - return []; - } - - public function countErrors(Request $request = null): int - { - if ($logger = $this->getDebugLogger()) { - return $logger->countErrors($request); - } - - return 0; - } - - public function clear(): void - { - if ($logger = $this->getDebugLogger()) { - $logger->clear(); - } - } - - public function reset(): void - { - $this->clear(); - - if ($this instanceof ResettableInterface) { - parent::reset(); - } - } - - public function removeDebugLogger(): void - { - foreach ($this->processors as $k => $processor) { - if ($processor instanceof DebugLoggerInterface) { - unset($this->processors[$k]); - } - } - - foreach ($this->handlers as $k => $handler) { - if ($handler instanceof DebugLoggerInterface) { - unset($this->handlers[$k]); - } - } - } - - /** - * Returns a DebugLoggerInterface instance if one is registered with this logger. - */ - private function getDebugLogger(): ?DebugLoggerInterface - { - foreach ($this->processors as $processor) { - if ($processor instanceof DebugLoggerInterface) { - return $processor; - } - } - - foreach ($this->handlers as $handler) { - if ($handler instanceof DebugLoggerInterface) { - return $handler; - } - } - - return null; - } -} diff --git a/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php b/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php deleted file mode 100644 index 1b44e18135941..0000000000000 --- a/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php +++ /dev/null @@ -1,142 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bridge\Monolog\Tests; - -use Monolog\Handler\TestHandler; -use Monolog\ResettableInterface; -use PHPUnit\Framework\TestCase; -use Symfony\Bridge\Monolog\Logger; -use Symfony\Bridge\Monolog\Processor\DebugProcessor; -use Symfony\Component\HttpFoundation\Request; - -/** - * @group legacy - */ -class LoggerTest extends TestCase -{ - public function testGetLogsWithoutDebugProcessor() - { - $handler = new TestHandler(); - $logger = new Logger(__METHOD__, [$handler]); - - $logger->error('error message'); - $this->assertSame([], $logger->getLogs()); - } - - public function testCountErrorsWithoutDebugProcessor() - { - $handler = new TestHandler(); - $logger = new Logger(__METHOD__, [$handler]); - - $logger->error('error message'); - $this->assertSame(0, $logger->countErrors()); - } - - public function testGetLogsWithDebugProcessor() - { - $handler = new TestHandler(); - $processor = new DebugProcessor(); - $logger = new Logger(__METHOD__, [$handler], [$processor]); - - $logger->error('error message'); - $this->assertCount(1, $logger->getLogs()); - } - - public function testCountErrorsWithDebugProcessor() - { - $handler = new TestHandler(); - $processor = new DebugProcessor(); - $logger = new Logger(__METHOD__, [$handler], [$processor]); - - $logger->debug('test message'); - $logger->info('test message'); - $logger->notice('test message'); - $logger->warning('test message'); - - $logger->error('test message'); - $logger->critical('test message'); - $logger->alert('test message'); - $logger->emergency('test message'); - - $this->assertSame(4, $logger->countErrors()); - } - - public function testGetLogsWithDebugProcessor2() - { - $handler = new TestHandler(); - $logger = new Logger('test', [$handler]); - $logger->pushProcessor(new DebugProcessor()); - - $logger->info('test'); - $this->assertCount(1, $logger->getLogs()); - [$record] = $logger->getLogs(); - - $this->assertEquals('test', $record['message']); - $this->assertEquals(200, $record['priority']); - } - - public function testGetLogsWithDebugProcessor3() - { - $request = new Request(); - $processor = $this->createMock(DebugProcessor::class); - $processor->expects($this->once())->method('getLogs')->with($request); - $processor->expects($this->once())->method('countErrors')->with($request); - - $handler = new TestHandler(); - $logger = new Logger('test', [$handler]); - $logger->pushProcessor($processor); - - $logger->getLogs($request); - $logger->countErrors($request); - } - - public function testClear() - { - $handler = new TestHandler(); - $logger = new Logger('test', [$handler]); - $logger->pushProcessor(new DebugProcessor()); - - $logger->info('test'); - $logger->clear(); - - $this->assertEmpty($logger->getLogs()); - $this->assertSame(0, $logger->countErrors()); - } - - public function testReset() - { - $handler = new TestHandler(); - $logger = new Logger('test', [$handler]); - $logger->pushProcessor(new DebugProcessor()); - - $logger->info('test'); - $logger->reset(); - - $this->assertEmpty($logger->getLogs()); - $this->assertSame(0, $logger->countErrors()); - if (class_exists(ResettableInterface::class)) { - $this->assertEmpty($handler->getRecords()); - } - } - - public function testInheritedClassCallGetLogsWithoutArgument() - { - $loggerChild = new ClassThatInheritLogger('test'); - $this->assertSame([], $loggerChild->getLogs()); - } - - public function testInheritedClassCallCountErrorsWithoutArgument() - { - $loggerChild = new ClassThatInheritLogger('test'); - $this->assertEquals(0, $loggerChild->countErrors()); - } -} diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index a233efb4e6948..aaf735d49116f 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -12,6 +12,8 @@ CHANGELOG `Symfony\Component\Serializer\Normalizer\NormalizerInterface` or implement `NormalizerAwareInterface` instead * Remove the `Http\Client\HttpClient` service, use `Psr\Http\Client\ClientInterface` instead * Remove the integration of Doctrine annotations, use native attributes instead + * Remove `EnableLoggerDebugModePass`, use argument `$debug` of HttpKernel's `Logger` instead + * Remove `AddDebugLogProcessorPass::configureLogger()`, use HttpKernel's `DebugLoggerConfigurator` instead 6.4 --- diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php index 68a1e51b01c07..1efdcb87ffe54 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddDebugLogProcessorPass.php @@ -32,16 +32,4 @@ public function process(ContainerBuilder $container): void $container->getDefinition('monolog.logger_prototype') ->setConfigurator([new Reference('debug.debug_logger_configurator'), 'pushDebugLogger']); } - - /** - * @deprecated since Symfony 6.4, use HttpKernel's DebugLoggerConfigurator instead - */ - public static function configureLogger(mixed $logger): void - { - trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s()" method is deprecated, use HttpKernel\'s DebugLoggerConfigurator instead.', __METHOD__); - - if (\is_object($logger) && method_exists($logger, 'removeDebugLogger') && \in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { - $logger->removeDebugLogger(); - } - } } diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/EnableLoggerDebugModePass.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/EnableLoggerDebugModePass.php deleted file mode 100644 index c1a5e444fdd00..0000000000000 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/EnableLoggerDebugModePass.php +++ /dev/null @@ -1,44 +0,0 @@ - - * - * 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; - -trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use argument $debug of HttpKernel\'s Logger instead.', EnableLoggerDebugModePass::class); - -use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\HttpKernel\Log\Logger; - -/** - * @deprecated since Symfony 6.4, use argument $debug of HttpKernel's Logger instead - */ -final class EnableLoggerDebugModePass implements CompilerPassInterface -{ - public function process(ContainerBuilder $container): void - { - 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)) { - $logger->enableDebug(); - } - } -}