ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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{
24 protected $socket;
25
33 public function __construct($host, $port = 514, $facility = LOG_USER, $level = Logger::DEBUG, $bubble = true)
34 {
35 parent::__construct($facility, $level, $bubble);
36
37 $this->socket = new UdpSocket($host, $port ?: 514);
38 }
39
40 protected function write(array $record)
41 {
42 $lines = $this->splitMessageIntoLines($record['formatted']);
43
44 $header = $this->makeCommonSyslogHeader($this->logLevels[$record['level']]);
45
46 foreach ($lines as $line) {
47 $this->socket->write($line, $header);
48 }
49 }
50
51 public function close()
52 {
53 $this->socket->close();
54 }
55
56 private function splitMessageIntoLines($message)
57 {
58 if (is_array($message)) {
59 $message = implode("\n", $message);
60 }
61
62 return preg_split('/$\R?^/m', $message);
63 }
64
68 protected function makeCommonSyslogHeader($severity)
69 {
70 $priority = $severity + $this->facility;
71
72 return "<$priority>1 ";
73 }
74
78 public function setSocket($socket)
79 {
80 $this->socket = $socket;
81 }
82}
An exception for terminatinating execution or to throw for unit testing.
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