$wgDebugDumpSql = false;
/**
- * Set to an array of log group keys to filenames.
+ * Map of string log group names to log destinations.
+ *
* If set, wfDebugLog() output for that group will go to that file instead
* of the regular $wgDebugLogFile. Useful for enabling selective logging
* in production.
+ *
+ * Log destinations may be string values specifying a filename or URI, or they
+ * may be filename or an associative array mapping 'target' to the desired
+ * filename. The associative array may also contain a 'sample' key with an
+ * integer value, specifying a sampling factor.
+ *
+ * @par Example:
+ * @code
+ * $wgDebugLogGroups['redis'] = '/var/log/mediawiki/redis.log';
+ * @endcode
+ *
+ * @par Advanced example:
+ * @code
+ * $wgDebugLogGroups['memcached'] = (
+ * 'target' => '/var/log/mediawiki/memcached.log',
+ * 'sample' => 1000, // log 1 message out of every 1,000.
+ * );
+ * @endcode
*/
$wgDebugLogGroups = array();
/**
* Send a line to a supplementary debug log file, if configured, or main debug log if not.
- * $wgDebugLogGroups[$logGroup] should be set to a filename to send to a separate log.
+ * To configure a supplementary log file, set $wgDebugLogGroups[$logGroup] to a string
+ * filename or an associative array mapping 'target' to the desired filename. The
+ * associative array may also contain a 'sample' key with an integer value, specifying
+ * a sampling factor.
+ *
+ * @since 1.23 support for sampling log messages via $wgDebugLogGroups.
*
* @param $logGroup String
* @param $text String
function wfDebugLog( $logGroup, $text, $public = true ) {
global $wgDebugLogGroups;
$text = trim( $text ) . "\n";
- if ( isset( $wgDebugLogGroups[$logGroup] ) ) {
- $time = wfTimestamp( TS_DB );
- $wiki = wfWikiID();
- $host = wfHostname();
- wfErrorLog( "$time $host $wiki: $text", $wgDebugLogGroups[$logGroup] );
- } elseif ( $public === true ) {
- wfDebug( "[$logGroup] $text", false );
+
+ if ( !isset( $wgDebugLogGroups[$logGroup] ) ) {
+ if ( $public === true ) {
+ wfDebug( "[$logGroup] $text", false );
+ }
+ return;
}
+
+ $logConfig = $wgDebugLogGroups[$logGroup];
+ if ( is_array( $logConfig ) ) {
+ if ( isset( $logConfig['sample'] ) && mt_rand( 1, $logConfig['sample'] ) !== 1 ) {
+ return;
+ }
+ $destination = $logConfig['destination'];
+ } else {
+ $destination = strval( $logConfig );
+ }
+
+ $time = wfTimestamp( TS_DB );
+ $wiki = wfWikiID();
+ $host = wfHostname();
+ wfErrorLog( "$time $host $wiki: $text", $destination );
}
/**