IAlex has uploaded a new change for review.
https://gerrit.wikimedia.org/r/95356
Change subject: Enhance the destination control parameter of wfDebug() and
wfDebugLog()
......................................................................
Enhance the destination control parameter of wfDebug() and wfDebugLog()
- It is now a string, making is more understandable that boolean values
and consistent between the two functions
- This adds a new possibility to wfDebugLog() to log the message either
on the specific log or the general one, but not to the debug toolbar
- Old boolean values are still recognised for backward compatibility
- Also send the messages passed to wfDebugLog() to the debug toolbar
when they are written to a specific log and not restricted to logs
- Updated the calls of and wfDebug() and wfDebugLog() with the last
parameter to change it into a string
- Changed the call to wfDebug() from MWDebug::sendWarning() to use
wfDebugLog() with 'log' as thrid parameter, so that those messages
can be logged separately from the main log and they don't show up
a second time on the "debug log" tab of the debug toolbar
Change-Id: I1be09d4c1d3408ed5b26a5db02691c17c0ec0926
---
M includes/AjaxResponse.php
M includes/Exception.php
M includes/GlobalFunctions.php
M includes/OutputPage.php
M includes/api/ApiMain.php
M includes/cache/HTMLFileCache.php
M includes/debug/Debug.php
M includes/specials/SpecialSearch.php
8 files changed, 70 insertions(+), 37 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/56/95356/1
diff --git a/includes/AjaxResponse.php b/includes/AjaxResponse.php
index d553652..3daf6a3 100644
--- a/includes/AjaxResponse.php
+++ b/includes/AjaxResponse.php
@@ -220,12 +220,12 @@
}
if ( !$wgCachePages ) {
- wfDebug( "$fname: CACHE DISABLED\n", false );
+ wfDebug( "$fname: CACHE DISABLED\n", 'log' );
return false;
}
if ( $wgUser->getOption( 'nocache' ) ) {
- wfDebug( "$fname: USER DISABLED CACHE\n", false );
+ wfDebug( "$fname: USER DISABLED CACHE\n", 'log' );
return false;
}
@@ -239,8 +239,8 @@
$modsince = preg_replace( '/;.*$/', '',
$_SERVER["HTTP_IF_MODIFIED_SINCE"] );
$modsinceTime = strtotime( $modsince );
$ismodsince = wfTimestamp( TS_MW, $modsinceTime ?
$modsinceTime : 1 );
- wfDebug( "$fname: -- client send If-Modified-Since: " .
$modsince . "\n", false );
- wfDebug( "$fname: -- we might send Last-Modified :
$lastmod\n", false );
+ wfDebug( "$fname: -- client send If-Modified-Since: " .
$modsince . "\n", 'log' );
+ wfDebug( "$fname: -- we might send Last-Modified :
$lastmod\n", 'log' );
if ( ( $ismodsince >= $timestamp ) &&
$wgUser->validateCache( $ismodsince ) && $ismodsince >= $wgCacheEpoch ) {
ini_set( 'zlib.output_compression', 0 );
@@ -248,15 +248,15 @@
$this->disable();
$this->mLastModified = $lastmod;
- wfDebug( "$fname: CACHED client: $ismodsince ;
user: {$wgUser->getTouched()} ; page: $timestamp ; site $wgCacheEpoch\n", false
);
+ wfDebug( "$fname: CACHED client: $ismodsince ;
user: {$wgUser->getTouched()} ; page: $timestamp ; site $wgCacheEpoch\n", 'log'
);
return true;
} else {
- wfDebug( "$fname: READY client: $ismodsince ;
user: {$wgUser->getTouched()} ; page: $timestamp ; site $wgCacheEpoch\n", false
);
+ wfDebug( "$fname: READY client: $ismodsince ;
user: {$wgUser->getTouched()} ; page: $timestamp ; site $wgCacheEpoch\n", 'log'
);
$this->mLastModified = $lastmod;
}
} else {
- wfDebug( "$fname: client did not send If-Modified-Since
header\n", false );
+ wfDebug( "$fname: client did not send If-Modified-Since
header\n", 'log' );
$this->mLastModified = $lastmod;
}
return false;
diff --git a/includes/Exception.php b/includes/Exception.php
index 008be15..cd2ef04 100644
--- a/includes/Exception.php
+++ b/includes/Exception.php
@@ -909,7 +909,7 @@
$json = self::jsonSerializeException( $e, false,
FormatJson::ALL_OK );
if ( $json !== false ) {
- wfDebugLog( 'exception-json', $json, false );
+ wfDebugLog( 'exception-json', $json, 'private'
);
}
}
diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php
index 1eb5c3e..bff27e4 100644
--- a/includes/GlobalFunctions.php
+++ b/includes/GlobalFunctions.php
@@ -924,13 +924,25 @@
* $wgDebugComments - if on, some debug items may appear in comments in the
HTML output.
*
* @param $text String
- * @param bool $logonly set true to avoid appearing in HTML when
$wgDebugComments is set
+ * @param string|bool $dest Destination of the message:
+ * - 'all': both to the log and HTML (debug toolbar or HTML comments)
+ * - 'log': only to the log and not in HTML
+ * For backward compatibility, it can also take a boolean:
+ * - true: same as 'all'
+ * - false: same as 'log'
*/
-function wfDebug( $text, $logonly = false ) {
+function wfDebug( $text, $dest = 'all' ) {
global $wgDebugLogFile, $wgProfileOnly, $wgDebugRawPage,
$wgDebugLogPrefix;
if ( !$wgDebugRawPage && wfIsDebugRawPage() ) {
return;
+ }
+
+ // Turn $dest into a string if it's a boolean (for b/c)
+ if ( $dest === true ) {
+ $dest = 'all';
+ } elseif ( $dest === false ) {
+ $dest = 'log';
}
$timer = wfDebugTimer();
@@ -938,7 +950,7 @@
$text = preg_replace( '/[^\n]/', $timer . '\0', $text, 1 );
}
- if ( !$logonly ) {
+ if ( $dest === 'all' ) {
MWDebug::debugMsg( $text );
}
@@ -1019,16 +1031,36 @@
* @param $text String
* @param bool $public whether to log the event in the public log if no private
* log file is specified, (default true)
+ * @param string|bool $dest Destination of the message:
+ * - 'all': both to the log and HTML (debug toolbar or HTML comments)
+ * - 'log': only to the log and not in HTML
+ * - 'private': only to the specifc log if set in $wgDebugLogGroups and
+ * discarded otherwise
+ * For backward compatibility, it can also take a boolean:
+ * - true: same as 'all'
+ * - false: same as 'private'
*/
-function wfDebugLog( $logGroup, $text, $public = true ) {
+function wfDebugLog( $logGroup, $text, $dest = 'all' ) {
global $wgDebugLogGroups;
+
$text = trim( $text ) . "\n";
+ // Turn $dest into a string if it's a boolean (for b/c)
+ if ( $dest === true ) {
+ $dest = 'all';
+ } elseif ( $dest === false ) {
+ $dest = 'private';
+ }
+
if ( !isset( $wgDebugLogGroups[$logGroup] ) ) {
- if ( $public === true ) {
- wfDebug( "[$logGroup] $text", false );
+ if ( $dest !== 'private' ) {
+ wfDebug( "[$logGroup] $text", $dest );
}
return;
+ }
+
+ if ( $dest === 'all' ) {
+ MWDebug::debugMsg( "[$logGroup] $text" );
}
$logConfig = $wgDebugLogGroups[$logGroup];
@@ -2772,9 +2804,9 @@
* @param array $limits optional array with limits(filesize, memory, time,
walltime)
* this overwrites the global wgShellMax* limits.
* @param array $options Array of options:
- * - duplicateStderr: Set this to true to duplicate stderr to stdout,
+ * - duplicateStderr: Set this to true to duplicate stderr to stdout,
* including errors from limit.sh
- *
+ *
* @return string collected stdout as a string
*/
function wfShellExec( $cmd, &$retval = null, $environ = array(),
@@ -2877,9 +2909,9 @@
$logMsg = false;
// According to the documentation, it is possible for stream_select()
- // to fail due to EINTR. I haven't managed to induce this in testing
- // despite sending various signals. If it did happen, the error
- // message would take the form:
+ // to fail due to EINTR. I haven't managed to induce this in testing
+ // despite sending various signals. If it did happen, the error
+ // message would take the form:
//
// stream_select(): unable to select [4]: Interrupted system call
(max_fd=5)
//
diff --git a/includes/OutputPage.php b/includes/OutputPage.php
index 5ffb802..79b9af0 100644
--- a/includes/OutputPage.php
+++ b/includes/OutputPage.php
@@ -689,11 +689,11 @@
return false;
}
if ( !$wgCachePages ) {
- wfDebug( __METHOD__ . ": CACHE DISABLED\n", false );
+ wfDebug( __METHOD__ . ": CACHE DISABLED\n", 'log' );
return false;
}
if ( $this->getUser()->getOption( 'nocache' ) ) {
- wfDebug( __METHOD__ . ": USER DISABLED CACHE\n", false
);
+ wfDebug( __METHOD__ . ": USER DISABLED CACHE\n", 'log'
);
return false;
}
@@ -714,7 +714,7 @@
$clientHeader = $this->getRequest()->getHeader(
'If-Modified-Since' );
if ( $clientHeader === false ) {
- wfDebug( __METHOD__ . ": client did not send
If-Modified-Since header\n", false );
+ wfDebug( __METHOD__ . ": client did not send
If-Modified-Since header\n", 'log' );
return false;
}
@@ -742,17 +742,17 @@
}
wfDebug( __METHOD__ . ": client sent If-Modified-Since: " .
- wfTimestamp( TS_ISO_8601, $clientHeaderTime ) . "\n",
false );
+ wfTimestamp( TS_ISO_8601, $clientHeaderTime ) . "\n",
'log' );
wfDebug( __METHOD__ . ": effective Last-Modified: " .
- wfTimestamp( TS_ISO_8601, $maxModified ) . "\n", false
);
+ wfTimestamp( TS_ISO_8601, $maxModified ) . "\n", 'log'
);
if ( $clientHeaderTime < $maxModified ) {
- wfDebug( __METHOD__ . ": STALE, $info\n", false );
+ wfDebug( __METHOD__ . ": STALE, $info\n", 'log' );
return false;
}
# Not modified
# Give a 304 response code and disable body output
- wfDebug( __METHOD__ . ": NOT MODIFIED, $info\n", false );
+ wfDebug( __METHOD__ . ": NOT MODIFIED, $info\n", 'log' );
ini_set( 'zlib.output_compression', 0 );
$this->getRequest()->response()->header( "HTTP/1.1 304 Not
Modified" );
$this->sendCacheControl();
@@ -1928,7 +1928,7 @@
# We'll purge the proxy cache
explicitly, but require end user agents
# to revalidate against the proxy on
each visit.
# Surrogate-Control controls our Squid,
Cache-Control downstream caches
- wfDebug( __METHOD__ . ": proxy caching
with ESI; {$this->mLastModified} **\n", false );
+ wfDebug( __METHOD__ . ": proxy caching
with ESI; {$this->mLastModified} **\n", 'log' );
# start with a shorter timeout for
initial testing
# header( 'Surrogate-Control:
max-age=2678400+2678400, content="ESI/1.0"');
$response->header( 'Surrogate-Control:
max-age=' . $wgSquidMaxage . '+' . $this->mSquidMaxage . ', content="ESI/1.0"'
);
@@ -1938,7 +1938,7 @@
# to revalidate against the proxy on
each visit.
# IMPORTANT! The Squid needs to replace
the Cache-Control header with
# Cache-Control: s-maxage=0,
must-revalidate, max-age=0
- wfDebug( __METHOD__ . ": local proxy
caching; {$this->mLastModified} **\n", false );
+ wfDebug( __METHOD__ . ": local proxy
caching; {$this->mLastModified} **\n", 'log' );
# start with a shorter timeout for
initial testing
# header( "Cache-Control:
s-maxage=2678400, must-revalidate, max-age=0" );
$response->header( 'Cache-Control:
s-maxage=' . $this->mSquidMaxage . ', must-revalidate, max-age=0' );
@@ -1946,7 +1946,7 @@
} else {
# We do want clients to cache if they can, but
they *must* check for updates
# on revisiting the page.
- wfDebug( __METHOD__ . ": private caching;
{$this->mLastModified} **\n", false );
+ wfDebug( __METHOD__ . ": private caching;
{$this->mLastModified} **\n", 'log' );
$response->header( 'Expires: ' . gmdate( 'D, d
M Y H:i:s', 0 ) . ' GMT' );
$response->header( "Cache-Control: private,
must-revalidate, max-age=0" );
}
@@ -1954,7 +1954,7 @@
$response->header( "Last-Modified:
{$this->mLastModified}" );
}
} else {
- wfDebug( __METHOD__ . ": no caching **\n", false );
+ wfDebug( __METHOD__ . ": no caching **\n", 'log' );
# In general, the absence of a last modified header
should be enough to prevent
# the client from using its cache. We send a few other
things just to make sure.
diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php
index c11f16c..2917073 100644
--- a/includes/api/ApiMain.php
+++ b/includes/api/ApiMain.php
@@ -867,7 +867,7 @@
}
}
$s .= "\n";
- wfDebugLog( 'api', $s, false );
+ wfDebugLog( 'api', $s, 'private' );
}
/**
diff --git a/includes/cache/HTMLFileCache.php b/includes/cache/HTMLFileCache.php
index ab37911..09b2782 100644
--- a/includes/cache/HTMLFileCache.php
+++ b/includes/cache/HTMLFileCache.php
@@ -163,7 +163,7 @@
return $text;
}
- wfDebug( __METHOD__ . "()\n", false );
+ wfDebug( __METHOD__ . "()\n", 'log' );
$now = wfTimestampNow();
if ( $this->useGzip() ) {
diff --git a/includes/debug/Debug.php b/includes/debug/Debug.php
index 6e9ccc4..1a144ec 100644
--- a/includes/debug/Debug.php
+++ b/includes/debug/Debug.php
@@ -155,7 +155,7 @@
$callerDescription = self::getCallerDescription( $callerOffset
);
- self::sendWarning( $msg, $callerDescription, $level );
+ self::sendWarning( $msg, $callerDescription, 'warning', $level
);
if ( self::$enabled ) {
self::$log[] = array(
@@ -227,7 +227,7 @@
if ( $sendToLog ) {
global $wgDevelopmentWarnings; // we could have a more
specific $wgDeprecationWarnings setting.
- self::sendWarning( $msg, $callerDescription,
$wgDevelopmentWarnings ? E_USER_DEPRECATED : false );
+ self::sendWarning( $msg, $callerDescription,
'deprecated', $wgDevelopmentWarnings ? E_USER_DEPRECATED : false );
}
if ( self::$enabled ) {
@@ -287,16 +287,17 @@
*
* @param $msg string Message to send
* @param $caller array caller description get from
getCallerDescription()
+ * @param $group string log group on which to send the message
* @param $level int|bool error level to use; set to false to not
trigger an error
*/
- private static function sendWarning( $msg, $caller, $level ) {
+ private static function sendWarning( $msg, $caller, $group, $level ) {
$msg .= ' [Called from ' . $caller['func'] . ' in ' .
$caller['file'] . ']';
if ( $level !== false ) {
trigger_error( $msg, $level );
}
- wfDebug( "$msg\n" );
+ wfDebugLog( $group, $msg, 'log' );
}
/**
diff --git a/includes/specials/SpecialSearch.php
b/includes/specials/SpecialSearch.php
index dd32656..96af4f3 100644
--- a/includes/specials/SpecialSearch.php
+++ b/includes/specials/SpecialSearch.php
@@ -201,7 +201,7 @@
if ( !is_null( $t ) ) {
global $wgGoToEdit;
wfRunHooks( 'SpecialSearchNogomatch', array( &$t ) );
- wfDebugLog( 'nogomatch', $t->getText(), false );
+ wfDebugLog( 'nogomatch', $t->getText(), 'private' );
# If the feature is enabled, go straight to the edit
page
if ( $wgGoToEdit ) {
--
To view, visit https://gerrit.wikimedia.org/r/95356
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1be09d4c1d3408ed5b26a5db02691c17c0ec0926
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: IAlex <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits