MediaWiki  1.33.0
Go to the documentation of this file.
1 <?php
21 namespace MediaWiki\Logger\Monolog;
23 use Monolog\Handler\SyslogUdpHandler;
24 use Monolog\Logger;
37 class MwlogHandler extends SyslogUdpHandler {
42  private $appprefix;
47  private $hostname;
59  public function __construct(
60  $appprefix,
61  $host,
62  $port = 514,
63  $facility = LOG_USER,
64  $level = Logger::DEBUG,
65  $bubble = true
66  ) {
67  parent::__construct( $host, $port, $facility, $level, $bubble );
68  $this->appprefix = $appprefix;
69  $this->hostname = php_uname( 'n' );
70  }
72  protected function syslogHeader( $severity, $app ) {
73  $pri = $severity + $this->facility;
75  // Goofy date format courtesy of RFC 3164 :(
76  // RFC 3164 actually specifies that the day of month should be space
77  // padded rather than unpadded but this seems to work with rsyslog and
78  // Logstash.
79  $timestamp = date( 'M j H:i:s' );
81  return "<{$pri}>{$timestamp} {$this->hostname} {$app}: ";
82  }
84  private function splitMessageIntoLines( $message ): array {
85  if ( is_array( $message ) ) {
86  $message = implode( "\n", $message );
87  }
89  return preg_split( '/$\R?^/m', (string)$message, -1, PREG_SPLIT_NO_EMPTY );
90  }
92  protected function write( array $record ) {
93  $lines = $this->splitMessageIntoLines( $record['formatted'] );
94  $header = $this->syslogHeader(
95  $this->logLevels[$record['level']],
96  $this->appprefix . $record['channel'] );
98  foreach ( $lines as $line ) {
99  $this->socket->write( $line, $header );
100  }
101  }
102 }
Log handler that will append the record's channel to a fixed 'application prefix' given at constructi...
Definition: MwlogHandler.php:37
Definition: AvroFormatter.php:21
write(array $record)
Definition: MwlogHandler.php:92
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
syslogHeader( $severity, $app)
Definition: MwlogHandler.php:72
__construct( $appprefix, $host, $port=514, $facility=LOG_USER, $level=Logger::DEBUG, $bubble=true)
Definition: MwlogHandler.php:59
Definition: MwlogHandler.php:42
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
Definition: router.php:61
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("", 2))
Definition: cdb.php:59
Definition: updateCredits.php:41
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
splitMessageIntoLines( $message)
Definition: MwlogHandler.php:84
Definition: MwlogHandler.php:47