Esempio n. 1
0
    /**
     * Prints out debug information about given variable.
     *
     * Only runs if debug level is greater than zero.
     *
     * @param mixed $var Variable to show debug information for.
     * @param bool $showHtml If set to true, the method prints the debug data in a browser-friendly way.
     * @param bool $showFrom If set to true, the method prints from where the function was called.
     * @return void
     * @link http://book.cakephp.org/2.0/en/development/debugging.html#basic-debugging
     * @link http://book.cakephp.org/2.0/en/core-libraries/global-constants-and-functions.html#debug
     */
    function debug($var, $showHtml = null, $showFrom = true)
    {
        if (Configure::read('debug')) {
            $file = '';
            $line = '';
            $lineInfo = '';
            if ($showFrom) {
                $trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
                $file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
                $line = $trace[0]['line'];
            }
            $html = <<<HTML
<div class="cake-debug-output">
%s
<pre class="cake-debug">
%s
</pre>
</div>
HTML;
            $text = <<<TEXT
%s
########## DEBUG ##########
%s
###########################

TEXT;
            $template = $html;
            if (php_sapi_name() === 'cli' || $showHtml === false) {
                $template = $text;
                if ($showFrom) {
                    $lineInfo = sprintf('%s (line %s)', $file, $line);
                }
            }
            if ($showHtml === null && $template !== $text) {
                $showHtml = true;
            }
            $var = Debugger::exportVar($var, 25);
            if ($showHtml) {
                $template = $html;
                $var = h($var);
                if ($showFrom) {
                    $lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line);
                }
            }
            printf($template, $lineInfo, $var);
        }
    }
 /**
  * Log an error.
  *
  * @param string $level The level name of the log.
  * @param array $data Array of error data.
  * @return void
  */
 protected function _logError($level, $data)
 {
     $message = sprintf('%s (%s): %s in [%s, line %s]', $data['error'], $data['code'], $data['description'], $data['file'], $data['line']);
     if (!empty($this->_options['trace'])) {
         $trace = Debugger::trace(array('start' => 1, 'format' => 'log'));
         $message .= "\nTrace:\n" . $trace . "\n";
     }
     return Log::write($level, $message);
 }
Esempio n. 3
0
 /**
  * test trace exclude
  *
  * @return void
  */
 public function testTraceExclude()
 {
     $result = Debugger::trace();
     $this->assertRegExp('/^Cake\\\\Test\\\\TestCase\\\\Utility\\\\DebuggerTest::testTraceExclude/', $result);
     $result = Debugger::trace(array('exclude' => array('Cake\\Test\\TestCase\\Utility\\DebuggerTest::testTraceExclude')));
     $this->assertNotRegExp('/^Cake\\\\Test\\\\TestCase\\\\Utility\\\\DebuggerTest::testTraceExclude/', $result);
 }