diff --git a/CHANGELOG.md b/CHANGELOG.md
index c580190f..60a552f0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,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)
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 86c9f870..cb29ecda 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,6 +163,7 @@
* - [level]: level name or int value, defaults to DEBUG
* - [bubble]: bool, defaults to true
* - [ident]: string, defaults to
+ * - [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
@@ -408,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
@@ -494,6 +496,7 @@ public function getConfigTreeBuilder()
->scalarNode('title')->defaultNull()->end() // pushover
->scalarNode('host')->defaultNull()->end() // syslogudp & hipchat
->scalarNode('port')->defaultValue(514)->end() // syslogudp
+ ->scalarNode('rfc')->defaultValue(SyslogUdpHandler::RFC5424)->end() // syslogudp
->arrayNode('publisher')
->canBeUnset()
->beforeNormalization()
diff --git a/DependencyInjection/MonologExtension.php b/DependencyInjection/MonologExtension.php
index d927ab01..b343b8ce 100644
--- a/DependencyInjection/MonologExtension.php
+++ b/DependencyInjection/MonologExtension.php
@@ -519,9 +519,18 @@ private function buildHandler(ContainerBuilder $container, $name, array $handler
$handler['level'],
$handler['bubble'],
]);
+
if ($handler['ident']) {
$definition->addArgument($handler['ident']);
+ } else {
+ $handler['ident'] = 'php';
+ $definition->addArgument($handler['ident']);
}
+
+ if (isset($handler['rfc'])) {
+ $definition->addArgument($handler['rfc']);
+ }
+
break;
case 'swift_mailer':
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 @@
+
diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php
index 7548af94..a68d1b5a 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,54 @@ 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',
+ 'ident' => null,
+ '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',
+ 'ident' => false,
+ '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']);
+ }
+
/**
* @group legacy
*/
diff --git a/Tests/DependencyInjection/MonologExtensionTest.php b/Tests/DependencyInjection/MonologExtensionTest.php
index 573523da..309700d6 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;
@@ -225,7 +226,32 @@ 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()
+ {
+ $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()