From 1378ce62d31b91afab060ec5b8b0cc35916eb71d Mon Sep 17 00:00:00 2001 From: Roan Kattouw Date: Thu, 27 Aug 2009 17:07:23 +0000 Subject: [PATCH] API: Add optional API request logging to a file or UDP; intending to use this on the cluster to get some data about API usage and things like which queries are expensive --- api.php | 13 +++++++++++++ includes/DefaultSettings.php | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/api.php b/api.php index 6c32baa86f..cf56858383 100644 --- a/api.php +++ b/api.php @@ -38,6 +38,7 @@ require (dirname(__FILE__) . '/includes/WebStart.php'); wfProfileIn('api.php'); +$starttime = microtime( true ); // URL safety checks // @@ -118,9 +119,21 @@ $processor->execute(); wfDoUpdates(); // Log what the user did, for book-keeping purposes. +$endtime = microtime( true ); wfProfileOut('api.php'); wfLogProfilingData(); +// Log the request +if ( $wgAPIRequestLog ) { + wfErrorLog( implode( ',', array( + wfTimestamp( TS_MW ), + $endtime - $starttime, + wfGetIP(), + wfArrayToCGI( $wgRequest->getValues() ) + ) ) . "\n", $wgAPIRequestLog ); + wfDebug( "Logged API request to $wgAPIRequestLog\n" ); +} + // Shut down the database wfGetLBFactory()->shutdown(); diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index dc657d9f12..c649938d57 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3822,6 +3822,12 @@ $wgAPIMaxResultSize = 8388608; */ $wgAPIMaxUncachedDiffs = 1; +/** + * Log file or URL (TCP or UDP) to log API requests to, or false to disable + * API request logging + */ +$wgAPIRequestLog = false; + /** * Parser test suite files to be run by parserTests.php when no specific * filename is passed to it. -- 2.20.1