/** * get the body for htmll message * * @access private * @author sakuragawa */ private function getHtml($message, $file, $line, $context = null) { $params = Router::getRequest(); $trace = Debugger::trace(array('start' => 2, 'format' => 'base')); $session = isset($_SESSION) ? $_SESSION : array(); $msg = array('<p><strong>', $message, '</strong></p>', '<p>', $file . '(' . $line . ')', '</p>', '', '<h2>', 'Backtrace:', '</h2>', '', '<pre>', self::dumper($trace), '</pre>', '', '<h2>', 'Request:', '</h2>', '', '<h3>URL</h3>', $this->url(), '<h3>Client IP</h3>', $this->getClientIp(), '<h3>Referer</h3>', env('HTTP_REFERER'), '<h3>Parameters</h3>', self::dumper($params), '<h3>Cake root</h3>', APP, '', '<h2>', 'Environment:', '</h2>', '', self::dumper($_SERVER), '', '<h2>', 'Session:', '</h2>', '', self::dumper($session), '', '<h2>', 'Cookie:', '</h2>', '', self::dumper($_COOKIE), '', '<h2>', 'Context:', '</h2>', '', self::dumper($context), ''); return join("", $msg); }
/** * Add a HTTP call to the data * * @param Request $request Call request * @param Response $response Call response * @param float $time duration of the call */ public static function addCall($request, $response, $time = null) { $calls = static::config('calls'); $trace = Debugger::trace(['start' => 2]); $calls[] = ['request' => ['uri' => (string) $request->getUri(), 'body' => $request->body(), 'method' => $request->getMethod(), 'headers' => $request->getHeaders(), 'content-type' => $request->getHeader('Content-Type')], 'response' => ['body' => $response->body(), 'status_code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'content-type' => $response->getHeader('Content-Type')], 'time' => $time, 'trace' => $trace]; static::drop('calls'); static::config('calls', $calls); }
/** * Add a HTTP call to the data * * @param $request * @param $response * @param $time */ public static function addCall($request, $response, $time = null) { $calls = static::config('calls'); $trace = Debugger::trace(['start' => 2]); $calls[] = ['request' => $request, 'response' => $response, 'time' => $time, 'trace' => $trace]; static::drop('calls'); static::config('calls', $calls); }
/** * exec method * * @param mixed $cmd '' * @param mixed &$out null * @return bool True if successful */ protected function _exec($cmd, &$out = null) { if (DS === '/') { $_out = exec($cmd . ' 2>&1', $out, $return); } else { $_out = exec($cmd, $out, $return); } if (Configure::read('debug')) { $source = Debugger::trace(array('depth' => 1, 'start' => 2)) . "\n"; //Log::write('system_calls_' . date('Y-m-d'), "\n" . $source . Debugger::exportVar(compact('cmd','out','return'))); //Log::write('system_calls', "\n" . $source . Debugger::exportVar(compact('cmd','out','return'))); } if ($return) { return false; } return $_out ? $_out : true; }
/** * Outputs a stack trace based on the supplied options. * * ### Options * * - `depth` - The number of stack frames to return. Defaults to 999 * - `args` - Should arguments for functions be shown? If true, the arguments for each method call * will be displayed. * - `start` - The stack frame to start generating a trace from. Defaults to 1 * * @param array $options Format for outputting stack trace * @return mixed Formatted stack trace */ function stackTrace(array $options = []) { if (!Configure::read('debug')) { return; } $options += ['start' => 0]; $options['start']++; echo Debugger::trace($options); }
/** * Log an error. * * @param string $level The level name of the log. * @param array $data Array of error data. * @return bool */ 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(['start' => 1, 'format' => 'log']); $message .= "\nTrace:\n" . $trace . "\n"; } $message .= "\n\n"; return Log::write($level, $message); }
/** * Tests that the stackTrace() method is a shortcut for Debugger::trace() * * @return void */ public function testStackTrace() { ob_start(); list($r, $expected) = [stackTrace(), \Cake\Error\Debugger::trace()]; $result = ob_get_clean(); $this->assertEquals($expected, $result); $opts = ['args' => true]; ob_start(); list($r, $expected) = [stackTrace($opts), \Cake\Error\Debugger::trace($opts)]; $result = ob_get_clean(); $this->assertEquals($expected, $result); }
/** * test trace exclude * * @return void */ public function testTraceExclude() { $result = Debugger::trace(); $this->assertRegExp('/^Cake\\\\Test\\\\TestCase\\\\Error\\\\DebuggerTest::testTraceExclude/', $result); $result = Debugger::trace(['exclude' => ['Cake\\Test\\TestCase\\Error\\DebuggerTest::testTraceExclude']]); $this->assertNotRegExp('/^Cake\\\\Test\\\\TestCase\\\\Error\\\\DebuggerTest::testTraceExclude/', $result); }
/** * Prints out debug information about given variable. * * Only runs if debug level is greater than zero. * * @param boolean $var Variable to show debug information for. * @param boolean $showHtml If set to true, the method prints the debug data in a browser-friendly way. * @param boolean $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 */ public static function debug($var, $showHtml = null, $showFrom = true) { if (Configure::read('debug') > 0) { // App::uses('Debugger', 'Utility'); $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"> <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 = htmlspecialchars($var); if ($showFrom) { $lineInfo = sprintf('<span><strong>%s</strong> (line <strong>%s</strong>)</span>', $file, $line); } } printf($template, $var); } }
/** * 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|null $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/3.0/en/development/debugging.html#basic-debugging * @link http://book.cakephp.org/3.0/en/core-libraries/global-constants-and-functions.html#debug */ public static function debug($var, $showHtml = null, $showFrom = true) { if (!Configure::read('debug')) { return; } $file = ''; $line = ''; $lineInfo = ''; if ($showFrom) { $trace = Debugger::trace(['start' => 1, 'depth' => 2, 'format' => 'array']); $search = [ROOT]; if (defined('CAKE_CORE_INCLUDE_PATH')) { array_unshift($search, CAKE_CORE_INCLUDE_PATH); } $file = str_replace($search, '', $trace[0]['file']); $line = $trace[0]['line']; } $html = <<<HTML <pre class="cake-debug"> %s </pre> </div> HTML; $text = <<<TEXT %s ########## DEBUG ########## %s ########################### TEXT; $template = $html; if (PHP_SAPI === '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, $var); }