MediaWiki master
MediaWiki\Logger\Monolog\LogstashFormatter Class Reference

Modified version of Monolog\Formatter\LogstashFormatter. More...

Inherits Monolog\Formatter\LogstashFormatter.

Inherited by MediaWiki\Logger\Monolog\CeeFormatter.

Collaboration diagram for MediaWiki\Logger\Monolog\LogstashFormatter:

Public Member Functions

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

Public Attributes

const V0 = 0
 
const V1 = 1
 

Protected Member Functions

 fixKeyConflicts (array $fields, array $context)
 Rename any context field that would otherwise overwrite a message key.
 
 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.
 
 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.
 
 formatV0 (array $record)
 Prevent key conflicts.
 
 formatV1 (array $record)
 Prevent key conflicts.
 
 normalizeException (\Throwable $e, int $depth=0)
 Use a more user-friendly trace format than Monolog\Formatter\NormalizerFormatter.
 

Protected Attributes

array $reservedKeys
 Keys which should not be used in log context.
 
int $version
 Logstash format version to use.
 

Detailed Description

Modified version of Monolog\Formatter\LogstashFormatter.

  • Squash the base message array, the context and extra subarrays into one. This can result in unfortunately named context fields overwriting other data (T145133).
  • Improve exception JSON-ification, which is done poorly by the standard class.
Since
1.29

Definition at line 15 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 
)

TODO: 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 49 of file LogstashFormatter.php.

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

Member Function Documentation

◆ fixKeyConflicts()

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

Rename any context field that would otherwise overwrite a message key.

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

Definition at line 209 of file LogstashFormatter.php.

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

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

◆ formatV0()

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

Prevent key conflicts.

Parameters
array$record
Returns
array

Definition at line 74 of file LogstashFormatter.php.

◆ formatV1()

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

Prevent key conflicts.

Parameters
array$record
Returns
array

Definition at line 142 of file LogstashFormatter.php.

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

◆ normalizeException()

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

Use a more user-friendly trace format than Monolog\Formatter\NormalizerFormatter.

Parameters
\\Throwable$e
int$depth
Returns
array

Definition at line 230 of file LogstashFormatter.php.

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

◆ $version

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

Logstash format version to use.

Definition at line 35 of file LogstashFormatter.php.

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

◆ V0

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

Definition at line 17 of file LogstashFormatter.php.

◆ V1

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

Definition at line 18 of file LogstashFormatter.php.


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