From 041e932c51d9c1c4fbe3fe9fe32e54df58f06138 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 4 Mar 2020 18:30:15 +0300 Subject: [PATCH 01/12] fixes #342 add rfc option for syslogudp handler --- DependencyInjection/Configuration.php | 2 ++ DependencyInjection/MonologExtension.php | 3 +++ 2 files changed, 5 insertions(+) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 86c9f870..9a454ca4 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -162,6 +162,7 @@ * - [level]: level name or int value, defaults to DEBUG * - [bubble]: bool, defaults to true * - [ident]: string, defaults to + * - [rfc]: string, defaults to * * - swift_mailer: * - from_email: optional if email_prototype is given @@ -494,6 +495,7 @@ public function getConfigTreeBuilder() ->scalarNode('title')->defaultNull()->end() // pushover ->scalarNode('host')->defaultNull()->end() // syslogudp & hipchat ->scalarNode('port')->defaultValue(514)->end() // syslogudp + ->scalarNode('rfc')->defaultNull()->end() // syslogudp ->arrayNode('publisher') ->canBeUnset() ->beforeNormalization() diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php index d927ab01..bfe23d47 100644 --- a/DependencyInjection/MonologExtension.php +++ b/DependencyInjection/MonologExtension.php @@ -522,6 +522,9 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler if ($handler['ident']) { $definition->addArgument($handler['ident']); } + if ($handler['rfc']) { + $definition->addArgument($handler['rfc']); + } break; case 'swift_mailer': From 040642aca8a9ea21486c930e52f58652c51acce0 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 5 Mar 2020 13:00:08 +0300 Subject: [PATCH 02/12] update rfc check --- DependencyInjection/MonologExtension.php | 2 +- Resources/config/schema/monolog-1.0.xsd | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php index bfe23d47..007f4762 100644 --- a/DependencyInjection/MonologExtension.php +++ b/DependencyInjection/MonologExtension.php @@ -522,7 +522,7 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler if ($handler['ident']) { $definition->addArgument($handler['ident']); } - if ($handler['rfc']) { + if (isset($handler['rfc'])) { $definition->addArgument($handler['rfc']); } break; diff --git a/Resources/config/schema/monolog-1.0.xsd b/Resources/config/schema/monolog-1.0.xsd index eb00e68a..8ff4d756 100644 --- a/Resources/config/schema/monolog-1.0.xsd +++ b/Resources/config/schema/monolog-1.0.xsd @@ -45,6 +45,7 @@ + From 194b07e76fb3f33b5c6af70422fc2bf79ba11752 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 9 Mar 2020 19:06:28 +0300 Subject: [PATCH 03/12] update node type & parameter description --- DependencyInjection/Configuration.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 9a454ca4..6ce177bb 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -162,7 +162,7 @@ * - [level]: level name or int value, defaults to DEBUG * - [bubble]: bool, defaults to true * - [ident]: string, defaults to - * - [rfc]: string, defaults to + * - [rfc]: int 0 (RFC3164) or 1 (RFC5424), defaults to 1 * * - swift_mailer: * - from_email: optional if email_prototype is given @@ -495,7 +495,7 @@ public function getConfigTreeBuilder() ->scalarNode('title')->defaultNull()->end() // pushover ->scalarNode('host')->defaultNull()->end() // syslogudp & hipchat ->scalarNode('port')->defaultValue(514)->end() // syslogudp - ->scalarNode('rfc')->defaultNull()->end() // syslogudp + ->integerNode('rfc')->defaultValue(1)->end() // syslogudp ->arrayNode('publisher') ->canBeUnset() ->beforeNormalization() From b91d639a53907829f287e6b40315ffe487a664b4 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 13 Jan 2021 14:16:32 +0300 Subject: [PATCH 04/12] make node is enum --- DependencyInjection/Configuration.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 6ce177bb..783bb4ff 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -16,6 +16,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; use Monolog\Logger; +use Monolog\Handler\SyslogUdpHandler; /** * This class contains the configuration information for the bundle @@ -162,7 +163,7 @@ * - [level]: level name or int value, defaults to DEBUG * - [bubble]: bool, defaults to true * - [ident]: string, defaults to - * - [rfc]: int 0 (RFC3164) or 1 (RFC5424), defaults to 1 + * - [rfc]: RFC3164 or RFC5424, defaults to RFC5424 * * - swift_mailer: * - from_email: optional if email_prototype is given @@ -495,7 +496,10 @@ public function getConfigTreeBuilder() ->scalarNode('title')->defaultNull()->end() // pushover ->scalarNode('host')->defaultNull()->end() // syslogudp & hipchat ->scalarNode('port')->defaultValue(514)->end() // syslogudp - ->integerNode('rfc')->defaultValue(1)->end() // syslogudp + ->enumNode('rfc') + ->values([SyslogUdpHandler::RFC5424, SyslogUdpHandler::RFC3164]) + ->defaultValue(SyslogUdpHandler::RFC5424) + ->end() // syslogudp ->arrayNode('publisher') ->canBeUnset() ->beforeNormalization() From 68687b0bc21e8f3f1657301a4c128326ba3e02f9 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 1 Feb 2021 19:56:51 +0300 Subject: [PATCH 05/12] test for syslogudp configuration --- DependencyInjection/Configuration.php | 2 +- .../DependencyInjection/ConfigurationTest.php | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 783bb4ff..9cde6ce1 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -163,7 +163,7 @@ * - [level]: level name or int value, defaults to DEBUG * - [bubble]: bool, defaults to true * - [ident]: string, defaults to - * - [rfc]: RFC3164 or RFC5424, defaults to RFC5424 + * - [rfc]: SyslogUdpHandler::RFC3164 (0) or SyslogUdpHandler::RFC5424 (1), defaults to SyslogUdpHandler::RFC5424 * * - swift_mailer: * - from_email: optional if email_prototype is given diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 7548af94..a51086e4 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\MonologBundle\Tests\DependencyInjection; +use Monolog\Handler\SyslogUdpHandler; use Monolog\Logger; use PHPUnit\Framework\TestCase; use Symfony\Bundle\MonologBundle\DependencyInjection\Configuration; @@ -407,6 +408,48 @@ public function testWithRedisHandler() $this->assertEquals('monolog_redis_test', $config['handlers']['redis']['redis']['key_name']); } + public function testWithSyslogUdpHandler() + { + $configs = [ + [ + 'handlers' => [ + 'syslogudp' => [ + 'type' => 'syslogudp', + 'host' => '127.0.0.1', + 'port' => 514, + 'facility' => 'USER', + 'level' => 'ERROR', + 'rfc' => SyslogUdpHandler::RFC3164 + ] + ] + ] + ]; + $config = $this->process($configs); + + $this->assertEquals('syslogudp', $config['handlers']['syslogudp']['type']); + $this->assertEquals('127.0.0.1', $config['handlers']['syslogudp']['host']); + $this->assertEquals(514, $config['handlers']['syslogudp']['port']); + $this->assertEquals(0, $config['handlers']['syslogudp']['rfc']); + + $configs = [ + [ + 'handlers' => [ + 'syslogudp' => [ + 'type' => 'syslogudp', + 'host' => '127.0.0.1', + 'port' => 514, + 'facility' => 'USER', + 'level' => 'ERROR', + 'rfc' => SyslogUdpHandler::RFC5424e + ] + ] + ] + ]; + + $this->expectException(InvalidConfigurationException::class); + $config = $this->process($configs); + } + /** * @group legacy */ From 36191efb3134db13a8d86c6b0a0c5e8d88729e84 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Mon, 1 Feb 2021 19:59:50 +0300 Subject: [PATCH 06/12] update test to check default value for rfc parameter --- .../DependencyInjection/ConfigurationTest.php | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index a51086e4..9a453b94 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -431,6 +431,26 @@ public function testWithSyslogUdpHandler() $this->assertEquals(514, $config['handlers']['syslogudp']['port']); $this->assertEquals(0, $config['handlers']['syslogudp']['rfc']); + $configs = [ + [ + 'handlers' => [ + 'syslogudp' => [ + 'type' => 'syslogudp', + 'host' => '127.0.0.1', + 'port' => 514, + 'facility' => 'USER', + 'level' => 'ERROR' + ] + ] + ] + ]; + $config = $this->process($configs); + + $this->assertEquals('syslogudp', $config['handlers']['syslogudp']['type']); + $this->assertEquals('127.0.0.1', $config['handlers']['syslogudp']['host']); + $this->assertEquals(514, $config['handlers']['syslogudp']['port']); + $this->assertEquals(1, $config['handlers']['syslogudp']['rfc']); + $configs = [ [ 'handlers' => [ @@ -440,7 +460,7 @@ public function testWithSyslogUdpHandler() 'port' => 514, 'facility' => 'USER', 'level' => 'ERROR', - 'rfc' => SyslogUdpHandler::RFC5424e + 'rfc' => 2 ] ] ] From b6757e16a090d6c805c75624db1548885f340113 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 25 Mar 2021 12:47:52 +0300 Subject: [PATCH 07/12] fix intendation, check ident parameter emptiness --- DependencyInjection/Configuration.php | 2 +- Tests/DependencyInjection/ConfigurationTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 9cde6ce1..a14ec6bc 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -499,7 +499,7 @@ public function getConfigTreeBuilder() ->enumNode('rfc') ->values([SyslogUdpHandler::RFC5424, SyslogUdpHandler::RFC3164]) ->defaultValue(SyslogUdpHandler::RFC5424) - ->end() // syslogudp + ->end() // syslogudp ->arrayNode('publisher') ->canBeUnset() ->beforeNormalization() diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 9a453b94..25cfdb4f 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -419,11 +419,13 @@ public function testWithSyslogUdpHandler() 'port' => 514, 'facility' => 'USER', 'level' => 'ERROR', + 'ident' => null, 'rfc' => SyslogUdpHandler::RFC3164 ] ] ] ]; + $config = $this->process($configs); $this->assertEquals('syslogudp', $config['handlers']['syslogudp']['type']); @@ -439,11 +441,13 @@ public function testWithSyslogUdpHandler() 'host' => '127.0.0.1', 'port' => 514, 'facility' => 'USER', + 'ident' => false, 'level' => 'ERROR' ] ] ] ]; + $config = $this->process($configs); $this->assertEquals('syslogudp', $config['handlers']['syslogudp']['type']); From 4a21b0d0d50177c7f0f4313f47e88ea512121c8f Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 31 Mar 2021 12:09:22 +0300 Subject: [PATCH 08/12] revert rfc field to scalar node (for SyslogUdpHandler::RFC5424e), update ident field validation --- DependencyInjection/Configuration.php | 9 +++---- DependencyInjection/MonologExtension.php | 8 +++++- .../MonologExtensionTest.php | 26 +++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index a14ec6bc..cb29ecda 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -163,7 +163,7 @@ * - [level]: level name or int value, defaults to DEBUG * - [bubble]: bool, defaults to true * - [ident]: string, defaults to - * - [rfc]: SyslogUdpHandler::RFC3164 (0) or SyslogUdpHandler::RFC5424 (1), defaults to SyslogUdpHandler::RFC5424 + * - [rfc]: SyslogUdpHandler::RFC3164 (0), SyslogUdpHandler::RFC5424 (1) or 2 (for SyslogUdpHandler::RFC5424e, monolog 1 does not support it) defaults to SyslogUdpHandler::RFC5424 * * - swift_mailer: * - from_email: optional if email_prototype is given @@ -410,7 +410,7 @@ public function getConfigTreeBuilder() ->booleanNode('use_locking')->defaultFalse()->end() // stream and rotating ->scalarNode('filename_format')->defaultValue('{filename}-{date}')->end() //rotating ->scalarNode('date_format')->defaultValue('Y-m-d')->end() //rotating - ->scalarNode('ident')->defaultFalse()->end() // syslog and syslogudp + ->scalarNode('ident')->defaultValue('php')->end() // syslog and syslogudp ->scalarNode('logopts')->defaultValue(LOG_PID)->end() // syslog ->scalarNode('facility')->defaultValue('user')->end() // syslog ->scalarNode('max_files')->defaultValue(0)->end() // rotating @@ -496,10 +496,7 @@ public function getConfigTreeBuilder() ->scalarNode('title')->defaultNull()->end() // pushover ->scalarNode('host')->defaultNull()->end() // syslogudp & hipchat ->scalarNode('port')->defaultValue(514)->end() // syslogudp - ->enumNode('rfc') - ->values([SyslogUdpHandler::RFC5424, SyslogUdpHandler::RFC3164]) - ->defaultValue(SyslogUdpHandler::RFC5424) - ->end() // syslogudp + ->scalarNode('rfc')->defaultValue(SyslogUdpHandler::RFC5424)->end() // syslogudp ->arrayNode('publisher') ->canBeUnset() ->beforeNormalization() diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php index 007f4762..f59b07c9 100644 --- a/DependencyInjection/MonologExtension.php +++ b/DependencyInjection/MonologExtension.php @@ -519,12 +519,18 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler $handler['level'], $handler['bubble'], ]); - if ($handler['ident']) { + + if (false === $handler['ident'] || null === $handler['ident']) { + $handler['ident'] = 'php'; + $definition->addArgument($handler['ident']); + } elseif ($handler['ident']) { $definition->addArgument($handler['ident']); } + if (isset($handler['rfc'])) { $definition->addArgument($handler['rfc']); } + break; case 'swift_mailer': diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php index 573523da..387a49eb 100644 --- a/Tests/DependencyInjection/MonologExtensionTest.php +++ b/Tests/DependencyInjection/MonologExtensionTest.php @@ -14,6 +14,7 @@ use InvalidArgumentException; use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; use Monolog\Handler\RollbarHandler; +use Monolog\Handler\SyslogUdpHandler; use Monolog\Logger; use Monolog\Processor\UidProcessor; use Symfony\Bridge\Monolog\Processor\SwitchUserTokenProcessor; @@ -228,6 +229,31 @@ public function testSyslogHandlerWithLogopts() $this->assertDICConstructorArguments($handler, [false, 'user', \Monolog\Logger::DEBUG, true, LOG_CONS]); } + public function testSyslogHandlerForEmptyIdent() + { + $container = $this->getContainer( + [ + [ + 'handlers' => [ + 'syslogudp' => [ + 'type' => 'syslogudp', + 'host' => '127.0.0.1', + 'port' => 514, + 'facility' => 'USER', + 'level' => 'ERROR', + 'ident' => null, + 'rfc' => SyslogUdpHandler::RFC5424, + ] + ] + ] + ] + ); + + $expectedArguments = ['127.0.0.1', 514, 'USER', true, 400, 'php', 1]; + $definition = $container->getDefinition('monolog.handler.syslogudp'); + $this->assertDICConstructorArguments($definition, $expectedArguments); + } + public function testRollbarHandlerCreatesNotifier() { $container = $this->getContainer([['handlers' => ['main' => ['type' => 'rollbar', 'token' => 'MY_TOKEN']]]]); From 5275fbd2c98078fa4da5f5d5743eeece5a607239 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 31 Mar 2021 12:18:37 +0300 Subject: [PATCH 09/12] update tests --- .../DependencyInjection/ConfigurationTest.php | 18 ------------------ .../MonologExtensionTest.php | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 25cfdb4f..a68d1b5a 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -454,24 +454,6 @@ public function testWithSyslogUdpHandler() $this->assertEquals('127.0.0.1', $config['handlers']['syslogudp']['host']); $this->assertEquals(514, $config['handlers']['syslogudp']['port']); $this->assertEquals(1, $config['handlers']['syslogudp']['rfc']); - - $configs = [ - [ - 'handlers' => [ - 'syslogudp' => [ - 'type' => 'syslogudp', - 'host' => '127.0.0.1', - 'port' => 514, - 'facility' => 'USER', - 'level' => 'ERROR', - 'rfc' => 2 - ] - ] - ] - ]; - - $this->expectException(InvalidConfigurationException::class); - $config = $this->process($configs); } /** diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php index 387a49eb..309700d6 100644 --- a/Tests/DependencyInjection/MonologExtensionTest.php +++ b/Tests/DependencyInjection/MonologExtensionTest.php @@ -226,7 +226,7 @@ public function testSyslogHandlerWithLogopts() $handler = $container->getDefinition('monolog.handler.main'); $this->assertDICDefinitionClass($handler, 'Monolog\Handler\SyslogHandler'); - $this->assertDICConstructorArguments($handler, [false, 'user', \Monolog\Logger::DEBUG, true, LOG_CONS]); + $this->assertDICConstructorArguments($handler, ['php', 'user', \Monolog\Logger::DEBUG, true, LOG_CONS]); } public function testSyslogHandlerForEmptyIdent() From ef995d26b8640b14e0c45887763d4974883240db Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 31 Mar 2021 12:22:24 +0300 Subject: [PATCH 10/12] Update DependencyInjection/MonologExtension.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jérémy Derussé --- DependencyInjection/MonologExtension.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php index f59b07c9..b343b8ce 100644 --- a/DependencyInjection/MonologExtension.php +++ b/DependencyInjection/MonologExtension.php @@ -520,10 +520,10 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler $handler['bubble'], ]); - if (false === $handler['ident'] || null === $handler['ident']) { - $handler['ident'] = 'php'; + if ($handler['ident']) { $definition->addArgument($handler['ident']); - } elseif ($handler['ident']) { + } else { + $handler['ident'] = 'php'; $definition->addArgument($handler['ident']); } From 0e3121d4b7c2ef8cbeae149a92b7444c0542b161 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 31 Mar 2021 12:25:05 +0300 Subject: [PATCH 11/12] update Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c580190f..4161ef8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.7.1 (2021-03-31) + +* Add ability to specify RFC for SyslogUdpHandler + ## 3.7.0 (xxxx-xx-xx) * Use `ActivationStrategy` instead of `actionLevel` when available From b8ae85a1b476447a75c01e74fc5cddba27d597ff Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Wed, 31 Mar 2021 12:35:23 +0300 Subject: [PATCH 12/12] update Changelog again, my bad :) --- CHANGELOG.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4161ef8e..60a552f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,3 @@ -## 3.7.1 (2021-03-31) - -* Add ability to specify RFC for SyslogUdpHandler - ## 3.7.0 (xxxx-xx-xx) * Use `ActivationStrategy` instead of `actionLevel` when available @@ -11,6 +7,7 @@ * Fix call to undefined method pushProcessor on handler that does not implement ProcessableHandlerInterface * Use "use_locking" option with rotating file handler * Add ability to specify custom Sentry hub service +* Add ability to specify RFC for SyslogUdpHandler ## 3.6.0 (2020-10-06)