MediaWiki  master
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:

Public Member Functions

 __construct (string $applicationName, ?string $systemName=null, string $extraKey='', string $contextKey='ctxt_', $version=self::V0)
 See T247675 for removing this override. More...
 
 format (array $record)
 

Public Attributes

const V0 = 0
 
const V1 = 1
 

Protected Member Functions

 fixKeyConflicts (array $fields, array $context)
 Check whether some context field would overwrite another message key. More...
 
 formatMonologV0 (array $record)
 Borrowed from monolog/monolog 1.25.3 https://github.com/Seldaek/monolog/blob/1.x/src/Monolog/Formatter/LogstashFormatter.php#L87-L128. More...
 
 formatMonologV1 (array $record)
 Borrowed mostly from monolog/monolog 1.25.3 https://github.com/Seldaek/monolog/blob/1.25.3/src/Monolog/Formatter/LogstashFormatter.php#L130-165. More...
 
 formatV0 (array $record)
 Prevent key conflicts. More...
 
 formatV1 (array $record)
 Prevent key conflicts. More...
 
 normalizeException (\Throwable $e, int $depth=0)
 Use a more user-friendly trace format than NormalizerFormatter. More...
 

Protected Attributes

array $reservedKeys
 Keys which should not be used in log context. More...
 
int $version
 Logstash format version to use. 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.

Since
1.29

Definition at line 13 of file LogstashFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Logger\Monolog\LogstashFormatter::__construct ( string  $applicationName,
?string  $systemName = null,
string  $extraKey = '',
string  $contextKey = 'ctxt_',
  $version = self::V0 
)

See T247675 for removing this override.

Parameters
string$applicationNameThe application that sends the data, used as the "type" field of logstash
string | null$systemNameThe system/machine name, used as the "source" field of logstash, defaults to the hostname of the machine
string$extraKeyThe key for extra keys inside logstash "fields", defaults to ''
string$contextKeyThe key for context keys inside logstash "fields", defaults
int$versionThe logstash format version to use, defaults to V0 to ''

Definition at line 47 of file LogstashFormatter.php.

References MediaWiki\Logger\Monolog\LogstashFormatter\$version.

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 205 of file LogstashFormatter.php.

References MediaWiki\$context.

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

◆ format()

MediaWiki\Logger\Monolog\LogstashFormatter::format ( array  $record)

◆ formatMonologV0()

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

Borrowed from monolog/monolog 1.25.3 https://github.com/Seldaek/monolog/blob/1.x/src/Monolog/Formatter/LogstashFormatter.php#L87-L128.

Parameters
array$record
Returns
array

Definition at line 91 of file LogstashFormatter.php.

Referenced by MediaWiki\Logger\Monolog\LogstashFormatter\formatV0().

◆ formatMonologV1()

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

Borrowed mostly from monolog/monolog 1.25.3 https://github.com/Seldaek/monolog/blob/1.25.3/src/Monolog/Formatter/LogstashFormatter.php#L130-165.

Parameters
array$record
Returns
array

Definition at line 157 of file LogstashFormatter.php.

Referenced by MediaWiki\Logger\Monolog\LogstashFormatter\formatV1().

◆ formatV0()

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

◆ formatV1()

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

Prevent key conflicts.

Parameters
array$record
Returns
array

Definition at line 138 of file LogstashFormatter.php.

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

◆ normalizeException()

MediaWiki\Logger\Monolog\LogstashFormatter::normalizeException ( \Throwable  $e,
int  $depth = 0 
)
protected

Use a more user-friendly trace format than NormalizerFormatter.

Parameters
\\Throwable$e
int$depth
Returns
array

Definition at line 225 of file LogstashFormatter.php.

References 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 19 of file LogstashFormatter.php.

◆ $version

int MediaWiki\Logger\Monolog\LogstashFormatter::$version
protected

Logstash format version to use.

Definition at line 33 of file LogstashFormatter.php.

Referenced by MediaWiki\Logger\Monolog\LogstashFormatter\__construct().

◆ V0

const MediaWiki\Logger\Monolog\LogstashFormatter::V0 = 0

Definition at line 15 of file LogstashFormatter.php.

◆ V1

const MediaWiki\Logger\Monolog\LogstashFormatter::V1 = 1

Definition at line 16 of file LogstashFormatter.php.


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