summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJordi Boggiano <j.boggiano@seld.be>2016-09-25 17:30:37 +0200
committerJordi Boggiano <j.boggiano@seld.be>2016-09-25 17:30:37 +0200
commit40b48910307be4216643a19e19491ece640bc59c (patch)
treeefc9da7d4c9c024a8a0eedf6951027d09a9dbe24
parent9f8d34afae0b734c82656748fdfb3c59c2bff3c8 (diff)
downloadmonolog-40b48910307be4216643a19e19491ece640bc59c.zip
monolog-40b48910307be4216643a19e19491ece640bc59c.tar.gz
monolog-40b48910307be4216643a19e19491ece640bc59c.tar.bz2
Make sure SyslogUdpHandler does not create empty frames where not necessary, fixes #841
-rw-r--r--src/Monolog/Handler/SyslogUdpHandler.php2
-rw-r--r--tests/Monolog/Handler/SyslogUdpHandlerTest.php18
2 files changed, 18 insertions, 2 deletions
diff --git a/src/Monolog/Handler/SyslogUdpHandler.php b/src/Monolog/Handler/SyslogUdpHandler.php
index b175cc3..74d946a 100644
--- a/src/Monolog/Handler/SyslogUdpHandler.php
+++ b/src/Monolog/Handler/SyslogUdpHandler.php
@@ -59,7 +59,7 @@ class SyslogUdpHandler extends AbstractSyslogHandler
$message = implode("\n", $message);
}
- return preg_split('/$\R?^/m', $message);
+ return preg_split('/$\R?^/m', $message, -1, PREG_SPLIT_NO_EMPTY);
}
/**
diff --git a/tests/Monolog/Handler/SyslogUdpHandlerTest.php b/tests/Monolog/Handler/SyslogUdpHandlerTest.php
index 497812b..aa4a334 100644
--- a/tests/Monolog/Handler/SyslogUdpHandlerTest.php
+++ b/tests/Monolog/Handler/SyslogUdpHandlerTest.php
@@ -11,10 +11,12 @@
namespace Monolog\Handler;
+use Monolog\TestCase;
+
/**
* @requires extension sockets
*/
-class SyslogUdpHandlerTest extends \PHPUnit_Framework_TestCase
+class SyslogUdpHandlerTest extends TestCase
{
/**
* @expectedException UnexpectedValueException
@@ -42,6 +44,20 @@ class SyslogUdpHandlerTest extends \PHPUnit_Framework_TestCase
$handler->handle($this->getRecordWithMessage("hej\nlol"));
}
+ public function testSplitWorksOnEmptyMsg()
+ {
+ $handler = new SyslogUdpHandler("127.0.0.1", 514, "authpriv");
+ $handler->setFormatter($this->getIdentityFormatter());
+
+ $socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', array('write'), array('lol', 'lol'));
+ $socket->expects($this->never())
+ ->method('write');
+
+ $handler->setSocket($socket);
+
+ $handler->handle($this->getRecordWithMessage(null));
+ }
+
protected function getRecordWithMessage($msg)
{
return array('message' => $msg, 'level' => \Monolog\Logger::WARNING, 'context' => null, 'extra' => array(), 'channel' => 'lol');