MediaWiki  1.30.0
MediaWiki\Logger\Monolog\LogstashFormatter Class Reference

LogstashFormatter squashes the base message array and the context and extras subarrays into one. More...

Inheritance diagram for MediaWiki\Logger\Monolog\LogstashFormatter:
Collaboration diagram for MediaWiki\Logger\Monolog\LogstashFormatter:

Protected Member Functions

 fixKeyConflicts (array $fields, array $context)
 Check whether some context field would overwrite another message key. More...
 
 formatV0 (array $record)
 Prevent key conflicts. More...
 
 formatV1 (array $record)
 Prevent key conflicts. More...
 
 normalizeException ( $e)
 Use a more user-friendly trace format than NormalizerFormatter. More...
 

Protected Attributes

array $reservedKeys
 Keys which should not be used in log context. More...
 

Detailed Description

LogstashFormatter squashes the base message array and the context and extras subarrays into one.

This can result in unfortunately named context fields overwriting other data (T145133). This class modifies the standard LogstashFormatter to rename such fields and flag the message. Also changes exception JSON-ification which is done poorly by the standard class.

Compatible with Monolog 1.x only.

Since
1.29

Definition at line 15 of file LogstashFormatter.php.

Member Function Documentation

◆ fixKeyConflicts()

MediaWiki\Logger\Monolog\LogstashFormatter::fixKeyConflicts ( array  $fields,
array  $context 
)
protected

Check whether some context field would overwrite another message key.

If so, rename and flag.

Parameters
array$fieldsFields to be sent to logstash
array$contextCopy of the original $record['context']
Returns
array Updated version of $fields

Definition at line 71 of file LogstashFormatter.php.

References MediaWiki\$context, and as.

Referenced by MediaWiki\Logger\Monolog\LogstashFormatter\formatV0(), and MediaWiki\Logger\Monolog\LogstashFormatter\formatV1().

◆ formatV0()

MediaWiki\Logger\Monolog\LogstashFormatter::formatV0 ( array  $record)
protected

Prevent key conflicts.

Parameters
array$record
Returns
array

Definition at line 33 of file LogstashFormatter.php.

References MediaWiki\$context, and MediaWiki\Logger\Monolog\LogstashFormatter\fixKeyConflicts().

◆ formatV1()

MediaWiki\Logger\Monolog\LogstashFormatter::formatV1 ( array  $record)
protected

Prevent key conflicts.

Parameters
array$record
Returns
array

Definition at line 51 of file LogstashFormatter.php.

References MediaWiki\$context, and MediaWiki\Logger\Monolog\LogstashFormatter\fixKeyConflicts().

◆ normalizeException()

MediaWiki\Logger\Monolog\LogstashFormatter::normalizeException (   $e)
protected

Use a more user-friendly trace format than NormalizerFormatter.

Parameters
\\Exception | \\Throwable$e
Returns
array

Definition at line 90 of file LogstashFormatter.php.

References $e, and MWExceptionHandler\getRedactedTraceAsString().

Member Data Documentation

◆ $reservedKeys

array MediaWiki\Logger\Monolog\LogstashFormatter::$reservedKeys
protected
Initial value:
= [
'message', 'channel', 'level', 'type',
'url', 'ip', 'http_method', 'server', 'referrer',
'host', 'wiki', 'reqId', 'mwversion',
'normalized_message',
]

Keys which should not be used in log context.

Definition at line 17 of file LogstashFormatter.php.


The documentation for this class was generated from the following file: