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