MediaWiki  master
LogstashFormatter.php
Go to the documentation of this file.
1 <?php
2 
4 
15 class LogstashFormatter extends \Monolog\Formatter\LogstashFormatter {
17  protected $reservedKeys = [
18  // from LogstashFormatter
19  'message', 'channel', 'level', 'type',
20  // from WebProcessor
21  'url', 'ip', 'http_method', 'server', 'referrer',
22  // from WikiProcessor
23  'host', 'wiki', 'reqId', 'mwversion',
24  // from config magic
25  'normalized_message',
26  ];
27 
33  protected function formatV0( array $record ) {
34  if ( $this->contextPrefix ) {
35  return parent::formatV0( $record );
36  }
37 
38  $context = !empty( $record['context'] ) ? $record['context'] : [];
39  $record['context'] = [];
40  $formatted = parent::formatV0( $record );
41 
42  $formatted['@fields'] = $this->fixKeyConflicts( $formatted['@fields'], $context );
43  return $formatted;
44  }
45 
51  protected function formatV1( array $record ) {
52  if ( $this->contextPrefix ) {
53  return parent::formatV1( $record );
54  }
55 
56  $context = !empty( $record['context'] ) ? $record['context'] : [];
57  $record['context'] = [];
58  $formatted = parent::formatV1( $record );
59 
60  $formatted = $this->fixKeyConflicts( $formatted, $context );
61  return $formatted;
62  }
63 
71  protected function fixKeyConflicts( array $fields, array $context ) {
72  foreach ( $context as $key => $val ) {
73  if (
74  in_array( $key, $this->reservedKeys, true ) &&
75  isset( $fields[$key] ) && $fields[$key] !== $val
76  ) {
77  $fields['logstash_formatter_key_conflict'][] = $key;
78  $key = 'c_' . $key;
79  }
80  $fields[$key] = $val;
81  }
82  return $fields;
83  }
84 
90  protected function normalizeException( $e ) {
91  if ( !$e instanceof \Exception && !$e instanceof \Throwable ) {
92  throw new \InvalidArgumentException( 'Exception/Throwable expected, got '
93  . gettype( $e ) . ' / ' . get_class( $e ) );
94  }
95 
96  $data = [
97  'class' => get_class( $e ),
98  'message' => $e->getMessage(),
99  'code' => $e->getCode(),
100  'file' => $e->getFile() . ':' . $e->getLine(),
102  ];
103 
104  $previous = $e->getPrevious();
105  if ( $previous ) {
106  $data['previous'] = $this->normalizeException( $previous );
107  }
108 
109  return $data;
110  }
111 }
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("192.168.0.1:11211", 2))
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException' returning false will NOT prevent logging $e
Definition: hooks.txt:2173
normalizeException( $e)
Use a more user-friendly trace format than NormalizerFormatter.
array $reservedKeys
Keys which should not be used in log context.
formatV1(array $record)
Prevent key conflicts.
LogstashFormatter squashes the base message array and the context and extras subarrays into one...
static getRedactedTraceAsString( $e)
Generate a string representation of an exception&#39;s stack trace.
IContextSource $context
Definition: MediaWiki.php:38
formatV0(array $record)
Prevent key conflicts.
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
fixKeyConflicts(array $fields, array $context)
Check whether some context field would overwrite another message key.
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