Esempio n. 1
0
/**
 * 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
 * $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 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
 *   For backward compatibility, it can also take a boolean:
 *     - true: same as 'all'
 *     - false: same as 'log'
 */
function wfDebug($text, $dest = 'all')
{
    global $wgDebugLogFile, $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();
    if ($timer !== '') {
        $text = preg_replace('/[^\\n]/', $timer . '\\0', $text, 1);
    }
    if ($dest === 'all') {
        MWDebug::debugMsg($text);
    }
    if ($wgDebugLogFile != '') {
        # 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);
    }
}
/**
 * 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);
        }
    }
}
/**
 * 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);
        }
    }
}
Esempio n. 4
0
/**
 * 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 $recursion = 0;
    static $cache = array();
    // Cache of unoutputted messages
    $text = wfDebugTimer() . $text;
    # Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet
    if (isset($_GET['action']) && $_GET['action'] == 'raw' && !$wgDebugRawPage) {
        return;
    }
    if (($wgDebugComments || $wgShowDebug) && !$logonly) {
        $cache[] = $text;
        if (!isset($wgOut)) {
            return;
        }
        if (!StubObject::isRealObject($wgOut)) {
            if ($recursion) {
                return;
            }
            $recursion++;
            $wgOut->_unstub();
            $recursion--;
        }
        // add the message and possible cached ones to the output
        array_map(array($wgOut, 'debug'), $cache);
        $cache = array();
    }
    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);
    }
}