mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-02 11:20:31 +02:00
Make sure SyslogUdpHandler does not create empty frames where not necessary, fixes #841
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -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');
|
||||
|
Reference in New Issue
Block a user