dépôts
/
lhc
/
web
/
wiklou.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
213ecf1
)
Warn when a log context accidentally overrides a log processor
author
Gergő Tisza
<gtisza@wikimedia.org>
Tue, 4 Oct 2016 00:24:58 +0000
(
00:24
+0000)
committer
Gergő Tisza
<gtisza@wikimedia.org>
Tue, 22 Nov 2016 03:07:05 +0000
(
03:07
+0000)
Bug: T145133
Change-Id: I6677dbf608aac1d7fd6036f5e51977d56ce2fc57
includes/debug/logger/monolog/WikiProcessor.php
patch
|
blob
|
history
diff --git
a/includes/debug/logger/monolog/WikiProcessor.php
b/includes/debug/logger/monolog/WikiProcessor.php
index
ad939a0
..
81e1e14
100644
(file)
--- a/
includes/debug/logger/monolog/WikiProcessor.php
+++ b/
includes/debug/logger/monolog/WikiProcessor.php
@@
-29,6
+29,17
@@
namespace MediaWiki\Logger\Monolog;
* @copyright © 2013 Bryan Davis and Wikimedia Foundation.
*/
class WikiProcessor {
* @copyright © 2013 Bryan Davis and Wikimedia Foundation.
*/
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 ) {
global $wgVersion;
*/
public function __invoke( array $record ) {
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'],
[
$record['extra'] = array_merge(
$record['extra'],
[
@@
-47,5
+67,4
@@
class WikiProcessor {
);
return $record;
}
);
return $record;
}
-
}
}