diff --git a/src/Worker/SocketListener.php b/src/Worker/SocketListener.php index c4df333..6ebcfac 100644 --- a/src/Worker/SocketListener.php +++ b/src/Worker/SocketListener.php @@ -110,6 +110,7 @@ class SocketListener foreach ($lines as $line) { $line = rtrim($line, "\r\n"); if ($line !== '') { + $line = preg_replace('/^\<\d+\>/', '', $line); ($this->onLine)($line, $id); } } @@ -126,15 +127,22 @@ class SocketListener if ($data === false) { return; } + fprintf(STDERR, "UDP recv %d bytes from %s:%d\n", strlen($buf), $from, $port); $lines = explode("\n", rtrim($buf, "\r\n")); foreach ($lines as $line) { $line = rtrim($line, "\r\n"); if ($line !== '') { - ($this->onLine)($line, $id); + $this->handleLineWithSyslog($line, $id); } } } + private function handleLineWithSyslog(string $line, int $sourceId): void + { + $line = preg_replace('/^\<\d+\>/', '', $line); + ($this->onLine)($line, $sourceId); + } + public function stop(): void { foreach ($this->tcpClients as $id => $clients) {