1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-23 01:26:11 +02:00

Fix syslog transport to follow the spec closer, fixes #476

This commit is contained in:
Jordi Boggiano
2014-12-17 10:46:48 +00:00
parent ebd0f73fbe
commit 5bee6fe56c
2 changed files with 13 additions and 40 deletions

View File

@@ -13,7 +13,7 @@ namespace Monolog\Handler\SyslogUdp;
class UdpSocket
{
const DATAGRAM_MAX_LENGTH = 2048;
const DATAGRAM_MAX_LENGTH = 65023;
public function __construct($ip, $port = 514)
{
@@ -24,11 +24,7 @@ class UdpSocket
public function write($line, $header = "")
{
$remaining = $line;
while (!is_null($remaining)) {
list($chunk, $remaining) = $this->splitLineIfNessesary($remaining, $header);
$this->send($chunk);
}
$this->send($this->assembleMessage($line, $header));
}
public function close()
@@ -41,22 +37,10 @@ class UdpSocket
socket_sendto($this->socket, $chunk, strlen($chunk), $flags = 0, $this->ip, $this->port);
}
protected function splitLineIfNessesary($line, $header)
protected function assembleMessage($line, $header)
{
if ($this->shouldSplitLine($line, $header)) {
$chunkSize = self::DATAGRAM_MAX_LENGTH - strlen($header);
$chunk = $header . substr($line, 0, $chunkSize);
$remaining = substr($line, $chunkSize);
} else {
$chunk = $header . $line;
$remaining = null;
}
$chunkSize = self::DATAGRAM_MAX_LENGTH - strlen($header);
return array($chunk, $remaining);
}
protected function shouldSplitLine($remaining, $header)
{
return strlen($header.$remaining) > self::DATAGRAM_MAX_LENGTH;
return $header . substr($line, 0, $chunkSize);
}
}