From ec1de9ed6c3a077c3936999f145c95e342717864 Mon Sep 17 00:00:00 2001 From: Tibor Rac Date: Sun, 3 Nov 2024 11:39:08 +0100 Subject: [PATCH 01/10] Add support for custom Gelf encoders in Monolog configuration This commit introduces the ability to specify custom encoders (`json` and `compressed_json`) for Gelf publishers in Monolog's configuration. --- src/DependencyInjection/Configuration.php | 8 +- src/DependencyInjection/MonologExtension.php | 19 ++++ .../DependencyInjection/ConfigurationTest.php | 22 +++++ .../MonologExtensionTest.php | 91 +++++++++++++++++++ 4 files changed, 139 insertions(+), 1 deletion(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index ae176445..e98e6216 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -52,7 +52,12 @@ * - [bubble]: bool, defaults to true * * - gelf: - * - publisher: {id: ...} or {hostname: ..., port: ..., chunk_size: ...} + * - publiser: + * - id: string, service id of a publisher implementation, optional if hostname is given + * - hostname: string, optional if id is given + * - [port]: int, defaults to 12201 + * - [chunk_size]: int, defaults to 1420 + * - [encoder]: string, its value can be 'json' or 'compressed_json' * - [level]: level name or int value, defaults to DEBUG * - [bubble]: bool, defaults to true * @@ -831,6 +836,7 @@ private function addGelfSection(ArrayNodeDefinition $handlerNode) ->scalarNode('hostname')->end() ->scalarNode('port')->defaultValue(12201)->end() ->scalarNode('chunk_size')->defaultValue(1420)->end() + ->scalarNode('encoder')->end() ->end() ->validate() ->ifTrue(function ($v) { diff --git a/src/DependencyInjection/MonologExtension.php b/src/DependencyInjection/MonologExtension.php index 0055750a..4dffb2fe 100644 --- a/src/DependencyInjection/MonologExtension.php +++ b/src/DependencyInjection/MonologExtension.php @@ -23,6 +23,7 @@ use Symfony\Bridge\Monolog\Processor\SwitchUserTokenProcessor; use Symfony\Bridge\Monolog\Processor\TokenProcessor; use Symfony\Bridge\Monolog\Processor\WebProcessor; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\ChildDefinition; @@ -221,10 +222,28 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler ]); $transport->setPublic(false); + if (isset($handler['publisher']['encoder'])) { + if ('compressed_json' === $handler['publisher']['encoder']) { + $encoderClass = 'Gelf\Encoder\CompressedJsonEncoder'; + } elseif ('json' === $handler['publisher']['encoder']) { + $encoderClass = 'Gelf\Encoder\JsonEncoder'; + } else { + throw new InvalidConfigurationException('The gelf message encoder must be either "compressed_json" or "json".'); + } + + $encoder = new Definition($encoderClass); + $encoder->setPublic(false); + + $transport->addMethodCall('setMessageEncoder', [$encoder]); + } + $publisher = new Definition('Gelf\Publisher', []); $publisher->addMethodCall('addTransport', [$transport]); $publisher->setPublic(false); } elseif (class_exists('Gelf\MessagePublisher')) { + if (isset($handler['publisher']['encoder']) && 'compressed_json' !== $handler['publisher']['encoder']) { + throw new InvalidConfigurationException('The Gelf\MessagePublisher publisher supports only the compressed json encoding. Omit the option to use the default encoding or use "compressed_json" as the encoder option.'); + } $publisher = new Definition('Gelf\MessagePublisher', [ $handler['publisher']['hostname'], $handler['publisher']['port'], diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index 0339e3bf..a3d6a43a 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -111,6 +111,28 @@ public function testGelfPublisherService($publisher) $this->assertEquals('gelf.publisher', $config['handlers']['gelf']['publisher']['id']); } + public function testGelfPublisherWithEncoder(): void + { + $configs = [ + [ + 'handlers' => [ + 'gelf' => [ + 'type' => 'gelf', + 'publisher' => [ + 'hostname' => 'localhost', + 'encoder' => 'compressed_json', + ], + ], + ], + ], + ]; + + $config = $this->process($configs); + + $this->assertEquals('localhost', $config['handlers']['gelf']['publisher']['hostname']); + $this->assertEquals('compressed_json', $config['handlers']['gelf']['publisher']['encoder']); + } + public function testArrays() { $configs = [ diff --git a/tests/DependencyInjection/MonologExtensionTest.php b/tests/DependencyInjection/MonologExtensionTest.php index 07604717..be8f31ee 100644 --- a/tests/DependencyInjection/MonologExtensionTest.php +++ b/tests/DependencyInjection/MonologExtensionTest.php @@ -189,6 +189,97 @@ public function testExceptionWhenUsingGelfWithoutPublisherHostname() $loader->load([['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => []]]]], $container); } + public function testExceptionWhenUsingLegacyGelfImplementationWithUnsupportedEncoder(): void + { + if (!class_exists('Gelf\MessagePublisher')) { + class_alias(\stdClass::class, 'Gelf\MessagePublisher'); + } + + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $this->expectException(InvalidConfigurationException::class); + + $loader->load([['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost', 'encoder' => 'json']]]]], $container); + } + + /** + * @dataProvider encoderOptionsProvider + */ + public function testLegacyGelfImplementationEncoderOption(array $config): void + { + if (!class_exists('Gelf\MessagePublisher')) { + class_alias(\stdClass::class, 'Gelf\MessagePublisher'); + } + + $container = $this->getContainer($config); + $this->assertTrue($container->hasDefinition('monolog.handler.gelf')); + + $handler = $container->getDefinition('monolog.handler.gelf'); + /** @var Definition $publisher */ + $publisher = $handler->getArguments()[0]; + + $this->assertDICConstructorArguments($publisher, ['localhost', 12201, 1420]); + } + + public function encoderOptionsProvider(): array + { + return [ + [ + [['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost', 'encoder' => 'compressed_json']]]]], + ], + [ + [['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost']]]]], + ], + ]; + } + + public function testExceptionWhenUsingGelfWithInvalidEncoder(): void + { + if (!class_exists('Gelf\Transport\UdpTransport')) { + class_alias(\stdClass::class, 'Gelf\Transport\UdpTransport'); + } + + $container = new ContainerBuilder(); + $loader = new MonologExtension(); + + $this->expectException(InvalidConfigurationException::class); + + $loader->load([['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost', 'encoder' => 'invalid_encoder']]]]], $container); + } + + /** + * @dataProvider gelfEncoderProvider + */ + public function testGelfWithEncoder($encoderValue, $expectedClass): void + { + if (!class_exists('Gelf\Transport\UdpTransport')) { + class_alias(\stdClass::class, 'Gelf\Transport\UdpTransport'); + } + + $container = $this->getContainer([['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost', 'encoder' => $encoderValue]]]]]); + $this->assertTrue($container->hasDefinition('monolog.handler.gelf')); + + $handler = $container->getDefinition('monolog.handler.gelf'); + /** @var Definition $publisher */ + $publisher = $handler->getArguments()[0]; + /** @var Definition $transport */ + $transport = $publisher->getMethodCalls()[0][1][0]; + $encoder = $transport->getMethodCalls()[0][1][0]; + + $this->assertDICConstructorArguments($transport, ['localhost', 12201, 1420]); + $this->assertDICDefinitionClass($encoder, $expectedClass); + $this->assertDICConstructorArguments($handler, [$publisher, 'DEBUG', true]); + } + + public function gelfEncoderProvider(): array + { + return [ + ['json', 'Gelf\Encoder\JsonEncoder'], + ['compressed_json', 'Gelf\Encoder\CompressedJsonEncoder'], + ]; + } + public function testExceptionWhenUsingServiceWithoutId() { $container = new ContainerBuilder(); From 5cb43067bc93c4264ad695e16344a6e79952b030 Mon Sep 17 00:00:00 2001 From: Tibor Rac Date: Sun, 3 Nov 2024 14:25:25 +0100 Subject: [PATCH 02/10] Fix compatibility issue, update class_alias to use DummyClassForClassExistsCheck Replaced instances of \stdClass in class_alias calls with DummyClassForClassExistsCheck as before php 8.3 only user created class can be aliased. # Conflicts: # tests/DependencyInjection/Fixtures/DummyClassForClassExistsCheck.php --- tests/DependencyInjection/MonologExtensionTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/DependencyInjection/MonologExtensionTest.php b/tests/DependencyInjection/MonologExtensionTest.php index be8f31ee..6cb5183e 100644 --- a/tests/DependencyInjection/MonologExtensionTest.php +++ b/tests/DependencyInjection/MonologExtensionTest.php @@ -23,6 +23,7 @@ use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessor; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessorWithPriority; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\RedeclareMethodProcessor; +use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\DummyClassForClassExistsCheck; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\ServiceWithChannel; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -192,7 +193,7 @@ public function testExceptionWhenUsingGelfWithoutPublisherHostname() public function testExceptionWhenUsingLegacyGelfImplementationWithUnsupportedEncoder(): void { if (!class_exists('Gelf\MessagePublisher')) { - class_alias(\stdClass::class, 'Gelf\MessagePublisher'); + class_alias(DummyClassForClassExistsCheck::class, 'Gelf\MessagePublisher'); } $container = new ContainerBuilder(); @@ -209,7 +210,7 @@ class_alias(\stdClass::class, 'Gelf\MessagePublisher'); public function testLegacyGelfImplementationEncoderOption(array $config): void { if (!class_exists('Gelf\MessagePublisher')) { - class_alias(\stdClass::class, 'Gelf\MessagePublisher'); + class_alias(DummyClassForClassExistsCheck::class, 'Gelf\MessagePublisher'); } $container = $this->getContainer($config); @@ -237,7 +238,7 @@ public function encoderOptionsProvider(): array public function testExceptionWhenUsingGelfWithInvalidEncoder(): void { if (!class_exists('Gelf\Transport\UdpTransport')) { - class_alias(\stdClass::class, 'Gelf\Transport\UdpTransport'); + class_alias(DummyClassForClassExistsCheck::class, 'Gelf\Transport\UdpTransport'); } $container = new ContainerBuilder(); @@ -254,7 +255,7 @@ class_alias(\stdClass::class, 'Gelf\Transport\UdpTransport'); public function testGelfWithEncoder($encoderValue, $expectedClass): void { if (!class_exists('Gelf\Transport\UdpTransport')) { - class_alias(\stdClass::class, 'Gelf\Transport\UdpTransport'); + class_alias(DummyClassForClassExistsCheck::class, 'Gelf\Transport\UdpTransport'); } $container = $this->getContainer([['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost', 'encoder' => $encoderValue]]]]]); From 7bf64b81cbc2e5c0910c54b01aa90da4d115c33e Mon Sep 17 00:00:00 2001 From: Tibor Rac Date: Mon, 4 Nov 2024 20:31:18 +0100 Subject: [PATCH 03/10] Fix typo in configuration comment --- src/DependencyInjection/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index e98e6216..a36673ae 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -52,7 +52,7 @@ * - [bubble]: bool, defaults to true * * - gelf: - * - publiser: + * - publisher: * - id: string, service id of a publisher implementation, optional if hostname is given * - hostname: string, optional if id is given * - [port]: int, defaults to 12201 From b234af682327f4a19a3eaaf68d7345bc24029096 Mon Sep 17 00:00:00 2001 From: Tibor Rac Date: Fri, 15 Nov 2024 23:22:02 +0100 Subject: [PATCH 04/10] Remove tests that fake Gelf classes --- .../MonologExtensionTest.php | 92 ------------------- 1 file changed, 92 deletions(-) diff --git a/tests/DependencyInjection/MonologExtensionTest.php b/tests/DependencyInjection/MonologExtensionTest.php index 6cb5183e..07604717 100644 --- a/tests/DependencyInjection/MonologExtensionTest.php +++ b/tests/DependencyInjection/MonologExtensionTest.php @@ -23,7 +23,6 @@ use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessor; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\FooProcessorWithPriority; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\AsMonologProcessor\RedeclareMethodProcessor; -use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\DummyClassForClassExistsCheck; use Symfony\Bundle\MonologBundle\Tests\DependencyInjection\Fixtures\ServiceWithChannel; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\DependencyInjection\ContainerBuilder; @@ -190,97 +189,6 @@ public function testExceptionWhenUsingGelfWithoutPublisherHostname() $loader->load([['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => []]]]], $container); } - public function testExceptionWhenUsingLegacyGelfImplementationWithUnsupportedEncoder(): void - { - if (!class_exists('Gelf\MessagePublisher')) { - class_alias(DummyClassForClassExistsCheck::class, 'Gelf\MessagePublisher'); - } - - $container = new ContainerBuilder(); - $loader = new MonologExtension(); - - $this->expectException(InvalidConfigurationException::class); - - $loader->load([['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost', 'encoder' => 'json']]]]], $container); - } - - /** - * @dataProvider encoderOptionsProvider - */ - public function testLegacyGelfImplementationEncoderOption(array $config): void - { - if (!class_exists('Gelf\MessagePublisher')) { - class_alias(DummyClassForClassExistsCheck::class, 'Gelf\MessagePublisher'); - } - - $container = $this->getContainer($config); - $this->assertTrue($container->hasDefinition('monolog.handler.gelf')); - - $handler = $container->getDefinition('monolog.handler.gelf'); - /** @var Definition $publisher */ - $publisher = $handler->getArguments()[0]; - - $this->assertDICConstructorArguments($publisher, ['localhost', 12201, 1420]); - } - - public function encoderOptionsProvider(): array - { - return [ - [ - [['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost', 'encoder' => 'compressed_json']]]]], - ], - [ - [['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost']]]]], - ], - ]; - } - - public function testExceptionWhenUsingGelfWithInvalidEncoder(): void - { - if (!class_exists('Gelf\Transport\UdpTransport')) { - class_alias(DummyClassForClassExistsCheck::class, 'Gelf\Transport\UdpTransport'); - } - - $container = new ContainerBuilder(); - $loader = new MonologExtension(); - - $this->expectException(InvalidConfigurationException::class); - - $loader->load([['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost', 'encoder' => 'invalid_encoder']]]]], $container); - } - - /** - * @dataProvider gelfEncoderProvider - */ - public function testGelfWithEncoder($encoderValue, $expectedClass): void - { - if (!class_exists('Gelf\Transport\UdpTransport')) { - class_alias(DummyClassForClassExistsCheck::class, 'Gelf\Transport\UdpTransport'); - } - - $container = $this->getContainer([['handlers' => ['gelf' => ['type' => 'gelf', 'publisher' => ['hostname' => 'localhost', 'encoder' => $encoderValue]]]]]); - $this->assertTrue($container->hasDefinition('monolog.handler.gelf')); - - $handler = $container->getDefinition('monolog.handler.gelf'); - /** @var Definition $publisher */ - $publisher = $handler->getArguments()[0]; - /** @var Definition $transport */ - $transport = $publisher->getMethodCalls()[0][1][0]; - $encoder = $transport->getMethodCalls()[0][1][0]; - - $this->assertDICConstructorArguments($transport, ['localhost', 12201, 1420]); - $this->assertDICDefinitionClass($encoder, $expectedClass); - $this->assertDICConstructorArguments($handler, [$publisher, 'DEBUG', true]); - } - - public function gelfEncoderProvider(): array - { - return [ - ['json', 'Gelf\Encoder\JsonEncoder'], - ['compressed_json', 'Gelf\Encoder\CompressedJsonEncoder'], - ]; - } - public function testExceptionWhenUsingServiceWithoutId() { $container = new ContainerBuilder(); From e86b0b4b8d53375356a62eb3c6bfbcd876fe39ef Mon Sep 17 00:00:00 2001 From: Tibor Rac Date: Sun, 9 Feb 2025 17:16:15 +0100 Subject: [PATCH 05/10] Update GELF config documentation for clarity --- src/DependencyInjection/Configuration.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index a36673ae..a27236e9 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -52,14 +52,17 @@ * - [bubble]: bool, defaults to true * * - gelf: - * - publisher: - * - id: string, service id of a publisher implementation, optional if hostname is given - * - hostname: string, optional if id is given - * - [port]: int, defaults to 12201 - * - [chunk_size]: int, defaults to 1420 - * - [encoder]: string, its value can be 'json' or 'compressed_json' - * - [level]: level name or int value, defaults to DEBUG - * - [bubble]: bool, defaults to true + * - publisher: (one of the following configurations) + * # Option 1: Service-based configuration + * - id: string, service id of a publisher implementation + * + * # Option 2: Direct connection configuration + * - hostname: string, server hostname + * - [port]: int, server port (default: 12201) + * - [chunk_size]: int, UDP packet size (default: 1420) + * - [encoder]: string, encoding format ('json' or 'compressed_json') + * - [level]: level name or int value, defaults to DEBUG + * - [bubble]: bool, defaults to true * * - chromephp: * - [level]: level name or int value, defaults to DEBUG From b9eedd621cba12d287750d075fcf0f4879c3a4d2 Mon Sep 17 00:00:00 2001 From: Tib-z Date: Wed, 17 Sep 2025 07:06:21 +0200 Subject: [PATCH 06/10] Fix indentation Co-authored-by: HypeMC <2445045+HypeMC@users.noreply.github.com> --- src/DependencyInjection/Configuration.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index a27236e9..1c1be81b 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -52,17 +52,17 @@ * - [bubble]: bool, defaults to true * * - gelf: - * - publisher: (one of the following configurations) - * # Option 1: Service-based configuration - * - id: string, service id of a publisher implementation + * - publisher: (one of the following configurations) + * # Option 1: Service-based configuration + * - id: string, service id of a publisher implementation * - * # Option 2: Direct connection configuration - * - hostname: string, server hostname - * - [port]: int, server port (default: 12201) - * - [chunk_size]: int, UDP packet size (default: 1420) - * - [encoder]: string, encoding format ('json' or 'compressed_json') - * - [level]: level name or int value, defaults to DEBUG - * - [bubble]: bool, defaults to true + * # Option 2: Direct connection configuration + * - hostname: string, server hostname + * - [port]: int, server port (default: 12201) + * - [chunk_size]: int, UDP packet size (default: 1420) + * - [encoder]: string, encoding format ('json' or 'compressed_json') + * - [level]: level name or int value, defaults to DEBUG + * - [bubble]: bool, defaults to true * * - chromephp: * - [level]: level name or int value, defaults to DEBUG From 234ea20d951a21c59c499c5632d43cc42b2e23a7 Mon Sep 17 00:00:00 2001 From: Tib-z Date: Wed, 17 Sep 2025 07:07:59 +0200 Subject: [PATCH 07/10] Change encoder config node from scalar to enum Co-authored-by: HypeMC <2445045+HypeMC@users.noreply.github.com> --- src/DependencyInjection/Configuration.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 1c1be81b..ac9d0897 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -839,7 +839,7 @@ private function addGelfSection(ArrayNodeDefinition $handlerNode) ->scalarNode('hostname')->end() ->scalarNode('port')->defaultValue(12201)->end() ->scalarNode('chunk_size')->defaultValue(1420)->end() - ->scalarNode('encoder')->end() + ->enumNode('encoder')->values(['json', 'compressed_json'])->end() ->end() ->validate() ->ifTrue(function ($v) { From 1d2d39c9fa5a989a2ea4fda6982dd8338c65bb03 Mon Sep 17 00:00:00 2001 From: Tib-z Date: Wed, 17 Sep 2025 07:10:01 +0200 Subject: [PATCH 08/10] Use RuntimeException instead of InvalidConfigurationException in extension Co-authored-by: HypeMC <2445045+HypeMC@users.noreply.github.com> --- src/DependencyInjection/MonologExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/MonologExtension.php b/src/DependencyInjection/MonologExtension.php index 4dffb2fe..56556fe2 100644 --- a/src/DependencyInjection/MonologExtension.php +++ b/src/DependencyInjection/MonologExtension.php @@ -228,7 +228,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler } elseif ('json' === $handler['publisher']['encoder']) { $encoderClass = 'Gelf\Encoder\JsonEncoder'; } else { - throw new InvalidConfigurationException('The gelf message encoder must be either "compressed_json" or "json".'); + throw new \RuntimeException('The gelf message encoder must be either "compressed_json" or "json".'); } $encoder = new Definition($encoderClass); From b2ee640cbdf30d42e535cda97ca60ec6525d5758 Mon Sep 17 00:00:00 2001 From: Tib-z Date: Sat, 27 Sep 2025 11:34:55 +0200 Subject: [PATCH 09/10] Use RuntimeException instead of InvalidConfigurationException in extension Co-authored-by: HypeMC <2445045+HypeMC@users.noreply.github.com> --- src/DependencyInjection/MonologExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DependencyInjection/MonologExtension.php b/src/DependencyInjection/MonologExtension.php index 56556fe2..a35e8344 100644 --- a/src/DependencyInjection/MonologExtension.php +++ b/src/DependencyInjection/MonologExtension.php @@ -242,7 +242,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler $publisher->setPublic(false); } elseif (class_exists('Gelf\MessagePublisher')) { if (isset($handler['publisher']['encoder']) && 'compressed_json' !== $handler['publisher']['encoder']) { - throw new InvalidConfigurationException('The Gelf\MessagePublisher publisher supports only the compressed json encoding. Omit the option to use the default encoding or use "compressed_json" as the encoder option.'); + throw new \RuntimeException('The Gelf\MessagePublisher publisher supports only the compressed json encoding. Omit the option to use the default encoding or use "compressed_json" as the encoder option.'); } $publisher = new Definition('Gelf\MessagePublisher', [ $handler['publisher']['hostname'], From e208cca444421b45f2aac37cfbc9c5d70d235331 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Wed, 1 Oct 2025 01:59:17 +0200 Subject: [PATCH 10/10] Fix CS --- CHANGELOG.md | 1 + src/DependencyInjection/MonologExtension.php | 1 - tests/DependencyInjection/ConfigurationTest.php | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6d70c73..34228c55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Drop support for Symfony < 6.4 * Add TelegramBotHandler `topic` support * Deprecate `sentry` and `raven` handler, use a `service` handler with [`sentry/sentry-symfony`](https://docs.sentry.io/platforms/php/guides/symfony/logs/) instead +* Add configuration for Gelf encoders ## 3.10.0 (2023-11-06) diff --git a/src/DependencyInjection/MonologExtension.php b/src/DependencyInjection/MonologExtension.php index a35e8344..2f45d218 100644 --- a/src/DependencyInjection/MonologExtension.php +++ b/src/DependencyInjection/MonologExtension.php @@ -23,7 +23,6 @@ use Symfony\Bridge\Monolog\Processor\SwitchUserTokenProcessor; use Symfony\Bridge\Monolog\Processor\TokenProcessor; use Symfony\Bridge\Monolog\Processor\WebProcessor; -use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Argument\BoundArgument; use Symfony\Component\DependencyInjection\ChildDefinition; diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index a3d6a43a..099d9d1e 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -111,7 +111,7 @@ public function testGelfPublisherService($publisher) $this->assertEquals('gelf.publisher', $config['handlers']['gelf']['publisher']['id']); } - public function testGelfPublisherWithEncoder(): void + public function testGelfPublisherWithEncoder() { $configs = [ [