/** * Sends a line to the debug log if enabled or, optionally, to a comment in output. * In normal operation this is a NOP. * * Controlling globals: * $wgDebugLogFile - points to the log file * $wgProfileOnly - if set, normal debug messages will not be recorded. * $wgDebugRawPage - if false, 'action=raw' hits will not result in debug output. * $wgDebugComments - if on, some debug items may appear in comments in the HTML output. * * @param $text String * @param $logonly Bool: set true to avoid appearing in HTML when $wgDebugComments is set */ function wfDebug($text, $logonly = false) { global $wgDebugLogFile, $wgProfileOnly, $wgDebugRawPage, $wgDebugLogPrefix; if (!$wgDebugRawPage && wfIsDebugRawPage()) { return; } $timer = wfDebugTimer(); if ($timer !== '') { $text = preg_replace('/[^\\n]/', $timer . '\\0', $text, 1); } if (!$logonly) { MWDebug::debugMsg($text); } if (wfRunHooks('Debug', array($text, null))) { if ($wgDebugLogFile != '' && !$wgProfileOnly) { # Strip unprintables; they can switch terminal modes when binary data # gets dumped, which is pretty annoying. $text = preg_replace('![\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]!', ' ', $text); $text = $wgDebugLogPrefix . $text; wfErrorLog($text, $wgDebugLogFile); } } }
/** * Send a line to a supplementary debug log file, if configured, or main debug log if not. * To configure a supplementary log file, set $wgDebugLogGroups[$logGroup] to a string * filename or an associative array mapping 'destination' 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 string $logGroup * @param string $text * @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, $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 ($dest !== 'private') { wfDebug("[{$logGroup}] {$text}", $dest); } return; } if ($dest === 'all') { MWDebug::debugMsg("[{$logGroup}] {$text}"); } $logConfig = $wgDebugLogGroups[$logGroup]; if ($logConfig === false) { return; } 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); }
/** * Sends a line to the debug log if enabled or, optionally, to a comment in output. * In normal operation this is a NOP. * * Controlling globals: * $wgDebugLogFile - points to the log file * $wgProfileOnly - if set, normal debug messages will not be recorded. * $wgDebugRawPage - if false, 'action=raw' hits will not result in debug output. * $wgDebugComments - if on, some debug items may appear in comments in the HTML output. * * @param $text String * @param $logonly Bool: set true to avoid appearing in HTML when $wgDebugComments is set */ function wfDebug($text, $logonly = false) { global $wgOut, $wgDebugLogFile, $wgDebugComments, $wgProfileOnly, $wgDebugRawPage; global $wgDebugLogPrefix, $wgShowDebug; static $cache = array(); // Cache of unoutputted messages $text = wfDebugTimer() . $text; if (!$wgDebugRawPage && wfIsDebugRawPage()) { return; } if (($wgDebugComments || $wgShowDebug) && !$logonly) { $cache[] = $text; if (isset($wgOut) && is_object($wgOut)) { // add the message and any cached messages to the output array_map(array($wgOut, 'debug'), $cache); $cache = array(); } } if (wfRunHooks('Debug', array($text, null))) { if ($wgDebugLogFile != '' && !$wgProfileOnly) { # Strip unprintables; they can switch terminal modes when binary data # gets dumped, which is pretty annoying. $text = preg_replace('![\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f]!', ' ', $text); $text = $wgDebugLogPrefix . $text; wfErrorLog($text, $wgDebugLogFile); } } MWDebug::debugMsg($text); }