MediaWiki REL1_30
SyslogHandler.php
Go to the documentation of this file.
1<?php
22
23use Monolog\Handler\SyslogUdpHandler;
24use Monolog\Logger;
25
48class SyslogHandler extends SyslogUdpHandler {
49
53 private $appname;
54
58 private $hostname;
59
70 public function __construct(
72 $host,
73 $port = 514,
74 $facility = LOG_USER,
75 $level = Logger::DEBUG,
76 $bubble = true
77 ) {
78 parent::__construct( $host, $port, $facility, $level, $bubble );
79 $this->appname = $appname;
80 $this->hostname = php_uname( 'n' );
81 }
82
83 protected function makeCommonSyslogHeader( $severity ) {
84 $pri = $severity + $this->facility;
85
86 // Goofy date format courtesy of RFC 3164 :(
87 // RFC 3164 actually specifies that the day of month should be space
88 // padded rather than unpadded but this seems to work with rsyslog and
89 // Logstash.
90 $timestamp = date( 'M j H:i:s' );
91
92 return "<{$pri}>{$timestamp} {$this->hostname} {$this->appname}: ";
93 }
94}
Log handler that supports sending log events to a syslog server using RFC 3164 formatted UDP packets.
__construct( $appname, $host, $port=514, $facility=LOG_USER, $level=Logger::DEBUG, $bubble=true)