ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
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 
12 namespace Monolog\Handler;
13 
14 use Monolog\Logger;
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 }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
makeCommonSyslogHeader($severity)
Make common syslog header (see rfc5424)
A Handler for logging to a remote syslogd server.
$header
Create styles array
The data for the language used.
setSocket($socket)
Inject your own socket, mainly used for testing.
__construct($host, $port=514, $facility=LOG_USER, $level=Logger::DEBUG, $bubble=true)