ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
SyslogUdpHandler.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <j.boggiano@seld.be>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Monolog\Handler;
13
16
23{
31 public function __construct($host, $port = 514, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true)
32 {
33 parent::__construct($facility, $level, $bubble);
34
35 $this->socket = new UdpSocket($host, $port ?: 514);
36 }
37
38 protected function write(array $record)
39 {
40 $lines = $this->splitMessageIntoLines($record['formatted']);
41
42 $header = $this->makeCommonSyslogHeader($this->logLevels[$record['level']]);
43
44 foreach ($lines as $line) {
45 $this->socket->write($line, $header);
46 }
47 }
48
49 public function close()
50 {
51 $this->socket->close();
52 }
53
54 private function splitMessageIntoLines($message)
55 {
56 if (is_array($message)) {
57 $message = implode("\n", $message);
58 }
59
60 return preg_split('/$\R?^/m', $message);
61 }
62
66 protected function makeCommonSyslogHeader($severity)
67 {
68 $priority = $severity + $this->facility;
69
70 return "<$priority>1 ";
71 }
72
76 public function setSocket($socket)
77 {
78 $this->socket = $socket;
79 }
80}
A Handler for logging to a remote syslogd server.
__construct($host, $port=514, $facility=LOG_USER, $level=Logger::DEBUG, $bubble=true)
makeCommonSyslogHeader($severity)
Make common syslog header (see rfc5424)
setSocket($socket)
Inject your own socket, mainly used for testing.
write(array $record)
Writes the record down to the log of the implementing handler.
Monolog log channel.
Definition: Logger.php:28
const DEBUG
Detailed debug information.
Definition: Logger.php:32
$header