1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-31 02:10:22 +02:00

Added SyslogUdpHandler.

This handler lets you log to a remote syslogd server via UPD. The
use-case here is having many webservers, and the need to gather log-
files on a centralized server.
This commit is contained in:
Jesper Skovgaard Nielsen
2013-10-31 09:41:00 +01:00
parent 0f3c054dff
commit e53d6040c0
4 changed files with 263 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
<?php
namespace Monolog\Handler;
use Monolog\TestCase;
class SyslogUdpHandlerTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException InvalidArgumentException
*/
public function testWeValidateFacilities()
{
$handler = new SyslogUdpHandler("loiwjefoiwjef", "ip");
}
public function testWeSplitIntoLines()
{
$handler = new SyslogUdpHandler("local5", "127.0.0.1");
$handler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter());
$socket = $this->getMock('\Monolog\Handler\SyslogUdp\UdpSocket', ['write'], ['lol', 'lol']);
$socket->expects($this->at(0))
->method('write')
->with("lol", "<172>: ");
$socket->expects($this->at(1))
->method('write')
->with("hej", "<172>: ");
$handler->setSocket($socket);
$handler->handle($this->getRecordWithMessage("hej\nlol"));
}
protected function getRecordWithMessage($msg)
{
return ['message' => $msg, 'level' => \Monolog\Logger::WARNING, 'context' => null, 'extra' => [], 'channel' => 'lol'];
}
}