Warn when a log context accidentally overrides a log processor
Bug: T145133 Change-Id: I6677dbf608aac1d7fd6036f5e51977d56ce2fc57
This commit is contained in:
parent
213ecf166a
commit
057b870b47
1 changed files with 20 additions and 1 deletions
|
|
@ -29,6 +29,17 @@ namespace MediaWiki\Logger\Monolog;
|
||||||
* @copyright © 2013 Bryan Davis and Wikimedia Foundation.
|
* @copyright © 2013 Bryan Davis and Wikimedia Foundation.
|
||||||
*/
|
*/
|
||||||
class WikiProcessor {
|
class WikiProcessor {
|
||||||
|
/** @var array Keys which should not be used in log context */
|
||||||
|
protected $reservedKeys = [
|
||||||
|
// from monolog:src/Monolog/Formatter/LogstashFormatter.php#L71-L88
|
||||||
|
'message', 'channel', 'level', 'type',
|
||||||
|
// from WebProcessor
|
||||||
|
'url', 'ip', 'http_method', 'server', 'referrer',
|
||||||
|
// from WikiProcessor
|
||||||
|
'host', 'wiki', 'reqId', 'mwversion',
|
||||||
|
// from config magic
|
||||||
|
'normalized_message',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $record
|
* @param array $record
|
||||||
|
|
@ -36,6 +47,15 @@ class WikiProcessor {
|
||||||
*/
|
*/
|
||||||
public function __invoke( array $record ) {
|
public function __invoke( array $record ) {
|
||||||
global $wgVersion;
|
global $wgVersion;
|
||||||
|
|
||||||
|
// some log aggregators such as Logstash will merge the log context into the main
|
||||||
|
// metadata and end up overwriting the data coming from processors
|
||||||
|
foreach ( $this->reservedKeys as $key ) {
|
||||||
|
if ( isset( $record['context'][$key] ) ) {
|
||||||
|
wfLogWarning( __METHOD__ . ": '$key' key overwritten in log context." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$record['extra'] = array_merge(
|
$record['extra'] = array_merge(
|
||||||
$record['extra'],
|
$record['extra'],
|
||||||
[
|
[
|
||||||
|
|
@ -47,5 +67,4 @@ class WikiProcessor {
|
||||||
);
|
);
|
||||||
return $record;
|
return $record;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue