MediaWiki  master
SyslogHandler.php
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Logger\Monolog;
22 
23 use DateTimeInterface;
24 use Monolog\Handler\SyslogUdpHandler;
25 use Monolog\Logger;
26 
49 class SyslogHandler extends SyslogUdpHandler {
50 
54  private $appname;
55 
59  private $hostname;
60 
71  public function __construct(
72  $appname,
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 }
MediaWiki\Logger\Monolog
Definition: BufferHandler.php:23
MediaWiki\Logger\Monolog\SyslogHandler\$hostname
string $hostname
Definition: SyslogHandler.php:59
MediaWiki\Logger\Monolog\SyslogHandler\makeCommonSyslogHeader
makeCommonSyslogHeader(int $severity, DateTimeInterface $datetime)
Definition: SyslogHandler.php:84
MediaWiki\Logger\Monolog\SyslogHandler
Log handler that supports sending log events to a syslog server using RFC 3164 formatted UDP packets.
Definition: SyslogHandler.php:49
MediaWiki\Logger\Monolog\SyslogHandler\$appname
string $appname
Definition: SyslogHandler.php:54
MediaWiki\Logger\Monolog\SyslogHandler\__construct
__construct( $appname, $host, $port=514, $facility=LOG_USER, $level=Logger::DEBUG, $bubble=true)
Definition: SyslogHandler.php:71