diff --git a/library/think/Debug.php b/library/think/Debug.php index 8dee74fe..28b6ab1e 100644 --- a/library/think/Debug.php +++ b/library/think/Debug.php @@ -201,12 +201,8 @@ class Debug if ($response instanceof Redirect) { //TODO 记录 - } elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) { - //TODO 记录 - } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { - //TODO 记录 } else { - $output = $trace->output(Log::getLog()); + $output = $trace->output($response, Log::getLog()); if (is_string($output)) { // trace调试信息注入 $content = $response->getContent(); diff --git a/library/think/debug/Console.php b/library/think/debug/Console.php index 6eacf23c..fa7e912a 100644 --- a/library/think/debug/Console.php +++ b/library/think/debug/Console.php @@ -15,6 +15,8 @@ use think\Cache; use think\Config; use think\Db; use think\Debug; +use think\Request; +use think\Response; /** * 浏览器调试输出 @@ -36,11 +38,20 @@ class Console /** * 调试输出接口 * @access public - * @param array $log 日志信息 + * @param Response $response Response对象 + * @param array $log 日志信息 * @return bool */ - public function output(array $log = []) + public function output(Response $response, array $log = []) { + $request = Request::instance(); + $contentType = $response->getHeader('Content-Type'); + $accept = $request->header('accept'); + if (strpos($accept, 'application/json') === 0 || $request->isAjax()) { + return false; + } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { + return false; + } // 获取基本信息 $runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME; $reqs = number_format(1 / $runtime, 2); diff --git a/library/think/debug/Html.php b/library/think/debug/Html.php index 7f16dc0e..8425cadc 100644 --- a/library/think/debug/Html.php +++ b/library/think/debug/Html.php @@ -15,6 +15,8 @@ use think\Cache; use think\Config; use think\Db; use think\Debug; +use think\Request; +use think\Response; /** * 页面Trace调试 @@ -36,12 +38,20 @@ class Html /** * 调试输出接口 * @access public - * @param array $log 日志信息 + * @param Response $response Response对象 + * @param array $log 日志信息 * @return bool */ - public function output(array $log = []) + public function output(Response $response, array $log = []) { - + $request = Request::instance(); + $contentType = $response->getHeader('Content-Type'); + $accept = $request->header('accept'); + if (strpos($accept, 'application/json') === 0 || $request->isAjax()) { + return false; + } elseif (!empty($contentType) && strpos($contentType, 'html') === false) { + return false; + } // 获取基本信息 $runtime = number_format(microtime(true), 8, '.', '') - THINK_START_TIME; $reqs = number_format(1 / $runtime, 2); diff --git a/library/think/debug/Socket.php b/library/think/debug/Socket.php index ae018a04..01aaa7c6 100644 --- a/library/think/debug/Socket.php +++ b/library/think/debug/Socket.php @@ -57,10 +57,11 @@ class Socket /** * 调试输出接口 * @access public - * @param array $logs 日志信息 + * @param Response $response Response对象 + * @param array $log 日志信息 * @return bool */ - public function output(array $logs = []) + public function output(Response $response, array $log = []) { if (!$this->check()) { return false;