From: Bryan Davis Date: Tue, 15 Nov 2016 22:18:08 +0000 (-0700) Subject: Throttler: improve log message compatibility with Monolog logger X-Git-Tag: 1.31.0-rc.0~4855^2 X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/gestion/rappel_supprimer.php?a=commitdiff_plain;h=a263b8d915ba5dcbbe301a5ef6496e64861645a2;p=lhc%2Fweb%2Fwiklou.git Throttler: improve log message compatibility with Monolog logger The `type` log event attribute is used in Wikimedia production logging to categorize log events by source (e.g. 'mediawiki', 'restbase', etc). Adding a `type` key to the logging context overwrites the default value of 'mediawiki'. Rename the key to `throttle` in the context and the message template. Change-Id: Ic274159774e43a8749f83c850fff7897956cf377 --- diff --git a/includes/auth/Throttler.php b/includes/auth/Throttler.php index f47c60655f..000b070522 100644 --- a/includes/auth/Throttler.php +++ b/includes/auth/Throttler.php @@ -135,7 +135,7 @@ class Throttler implements LoggerAwareInterface { $this->cache->incr( $throttleKey ); } else { // throttled $this->logRejection( [ - 'type' => $this->type, + 'throttle' => $this->type, 'index' => $index, 'ip' => $ipKey, 'username' => $username, @@ -191,7 +191,7 @@ class Throttler implements LoggerAwareInterface { } protected function logRejection( array $context ) { - $logMsg = 'Throttle {type} hit, throttled for {expiry} seconds due to {count} attempts ' + $logMsg = 'Throttle {throttle} hit, throttled for {expiry} seconds due to {count} attempts ' . 'from username {username} and IP {ip}'; // If we are hitting a throttle for >= warningLimit attempts, it is much more likely to be diff --git a/tests/phpunit/includes/auth/ThrottlerTest.php b/tests/phpunit/includes/auth/ThrottlerTest.php index 5806003f64..c945885c76 100644 --- a/tests/phpunit/includes/auth/ThrottlerTest.php +++ b/tests/phpunit/includes/auth/ThrottlerTest.php @@ -196,7 +196,7 @@ class ThrottlerTest extends \MediaWikiTestCase { ->setMethods( [ 'log' ] ) ->getMockForAbstractClass(); $logger->expects( $this->once() )->method( 'log' )->with( $this->anything(), $this->anything(), [ - 'type' => 'custom', + 'throttle' => 'custom', 'index' => 0, 'ip' => '1.2.3.4', 'username' => 'SomeUser',