mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-07 23:22:48 +08:00
增加app_trace 参数用于配置是否开启trace调试
This commit is contained in:
@@ -9,6 +9,8 @@ return [
|
|||||||
'app_namespace' => 'app',
|
'app_namespace' => 'app',
|
||||||
// 应用调试模式
|
// 应用调试模式
|
||||||
'app_debug' => true,
|
'app_debug' => true,
|
||||||
|
// 应用Trace
|
||||||
|
'app_trace' => false,
|
||||||
// 应用模式状态
|
// 应用模式状态
|
||||||
'app_status' => '',
|
'app_status' => '',
|
||||||
// 是否支持多模块
|
// 是否支持多模块
|
||||||
@@ -134,24 +136,26 @@ return [
|
|||||||
'error_message' => '页面错误!请稍后再试~',
|
'error_message' => '页面错误!请稍后再试~',
|
||||||
// 显示错误信息
|
// 显示错误信息
|
||||||
'show_error_msg' => false,
|
'show_error_msg' => false,
|
||||||
|
// 异常处理handle类 留空使用 \think\exception\Handle
|
||||||
|
'exception_handle' => '',
|
||||||
|
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | 日志设置
|
// | 日志设置
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
'log' => [
|
'log' => [
|
||||||
// 日志记录方式,支持 file sae
|
// 日志记录方式,内置 file sae 支持扩展
|
||||||
'type' => 'File',
|
'type' => 'File',
|
||||||
// 日志保存目录
|
// 日志保存目录
|
||||||
'path' => LOG_PATH,
|
'path' => LOG_PATH,
|
||||||
],
|
],
|
||||||
|
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | Trace设置
|
// | Trace设置 开启 app_trace 后 有效
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
'trace' => [
|
'trace' => [
|
||||||
// 支持Html Socket Console 设为false则不显示
|
// 内置Html Socket Console 支持扩展
|
||||||
'type' => false,
|
'type' => 'Html',
|
||||||
],
|
],
|
||||||
|
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
@@ -245,6 +249,7 @@ return [
|
|||||||
// 自动写入时间戳字段
|
// 自动写入时间戳字段
|
||||||
'auto_timestamp' => false,
|
'auto_timestamp' => false,
|
||||||
],
|
],
|
||||||
|
|
||||||
//分页配置
|
//分页配置
|
||||||
'paginate' => [
|
'paginate' => [
|
||||||
'type' => 'bootstrap',
|
'type' => 'bootstrap',
|
||||||
|
|||||||
@@ -155,7 +155,9 @@ class App
|
|||||||
Hook::listen('app_end', $response);
|
Hook::listen('app_end', $response);
|
||||||
|
|
||||||
// Trace调试注入
|
// Trace调试注入
|
||||||
Debug::inject($response);
|
if (Config::get('app_trace')) {
|
||||||
|
Debug::inject($response);
|
||||||
|
}
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,40 +186,37 @@ class Debug
|
|||||||
|
|
||||||
public static function inject(Response $response)
|
public static function inject(Response $response)
|
||||||
{
|
{
|
||||||
$config = Config::get('trace');
|
$config = Config::get('trace');
|
||||||
$type = isset($config['type']) ? $config['type'] : 'Html';
|
$type = isset($config['type']) ? $config['type'] : 'Html';
|
||||||
|
$request = Request::instance();
|
||||||
|
$accept = $request->header('accept');
|
||||||
|
$contentType = $response->getHeader('Content-Type');
|
||||||
|
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
|
||||||
|
unset($config['type']);
|
||||||
|
if (class_exists($class)) {
|
||||||
|
$trace = new $class($config);
|
||||||
|
} else {
|
||||||
|
throw new ClassNotFoundException('class not exists:' . $class, $class);
|
||||||
|
}
|
||||||
|
|
||||||
if (false !== $type) {
|
if ($response instanceof Redirect) {
|
||||||
$request = Request::instance();
|
//TODO 记录
|
||||||
$accept = $request->header('accept');
|
} elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) {
|
||||||
$contentType = $response->getHeader('Content-Type');
|
//TODO 记录
|
||||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\debug\\' . ucwords($type);
|
} elseif (!empty($contentType) && strpos($contentType, 'html') === false) {
|
||||||
unset($config['type']);
|
//TODO 记录
|
||||||
if (class_exists($class)) {
|
} else {
|
||||||
$trace = new $class($config);
|
$output = $trace->output(Log::getLog());
|
||||||
} else {
|
if (is_string($output)) {
|
||||||
throw new ClassNotFoundException('class not exists:' . $class, $class);
|
// trace调试信息注入
|
||||||
}
|
$content = $response->getContent();
|
||||||
|
$pos = strripos($content, '</body>');
|
||||||
if ($response instanceof Redirect) {
|
if (false !== $pos) {
|
||||||
//TODO 记录
|
$content = substr($content, 0, $pos) . $output . substr($content, $pos);
|
||||||
} elseif (strpos($accept, 'application/json') === 0 || $request->isAjax()) {
|
} else {
|
||||||
//TODO 记录
|
$content = $content . $output;
|
||||||
} elseif (!empty($contentType) && strpos($contentType, 'html') === false) {
|
|
||||||
//TODO 记录
|
|
||||||
} else {
|
|
||||||
$output = $trace->output(Log::getLog());
|
|
||||||
if (is_string($output)) {
|
|
||||||
// trace调试信息注入
|
|
||||||
$content = $response->getContent();
|
|
||||||
$pos = strripos($content, '</body>');
|
|
||||||
if (false !== $pos) {
|
|
||||||
$content = substr($content, 0, $pos) . $output . substr($content, $pos);
|
|
||||||
} else {
|
|
||||||
$content = $content . $output;
|
|
||||||
}
|
|
||||||
$response->content($content);
|
|
||||||
}
|
}
|
||||||
|
$response->content($content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class Error
|
|||||||
if (error_reporting() & $errno) {
|
if (error_reporting() & $errno) {
|
||||||
// 将错误信息托管至 think\exception\ErrorException
|
// 将错误信息托管至 think\exception\ErrorException
|
||||||
throw $exception;
|
throw $exception;
|
||||||
}else{
|
} else {
|
||||||
self::getExceptionHandler()->report($exception);
|
self::getExceptionHandler()->report($exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,24 +98,20 @@ class Error
|
|||||||
/**
|
/**
|
||||||
* Get an instance of the exception handler.
|
* Get an instance of the exception handler.
|
||||||
*
|
*
|
||||||
* @return \think\exception\Handle
|
* @return Handle
|
||||||
*/
|
*/
|
||||||
public static function getExceptionHandler()
|
public static function getExceptionHandler()
|
||||||
{
|
{
|
||||||
static $handle;
|
static $handle;
|
||||||
|
|
||||||
if (!$handle) {
|
if (!$handle) {
|
||||||
|
// 异常处理handle
|
||||||
if ($class = Config::get('exception_handle')) {
|
$class = Config::get('exception_handle');
|
||||||
if (class_exists($class) && is_subclass_of($class, "\\think\\exception\\Handle")) {
|
if ($class && class_exists($class) && is_subclass_of($class, "\\think\\exception\\Handle")) {
|
||||||
$handle = new $class;
|
$handle = new $class;
|
||||||
}
|
} else {
|
||||||
}
|
$handle = new Handle;
|
||||||
if (!$handle) {
|
|
||||||
$handle = new Handle();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $handle;
|
return $handle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,13 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace think;
|
namespace think;
|
||||||
|
|
||||||
use think\exception\ClassNotFoundException;
|
use think\exception\ClassNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Log
|
* Class Log
|
||||||
* @package think
|
* @package think
|
||||||
*
|
*
|
||||||
* @method void log($msg) static
|
* @method void log($msg) static
|
||||||
* @method void error($msg) static
|
* @method void error($msg) static
|
||||||
* @method void info($msg) static
|
* @method void info($msg) static
|
||||||
@@ -48,13 +49,13 @@ class Log
|
|||||||
* 日志初始化
|
* 日志初始化
|
||||||
* @param array $config
|
* @param array $config
|
||||||
*/
|
*/
|
||||||
public static function init($config = [])
|
public static function init($config = [])
|
||||||
{
|
{
|
||||||
$type = isset($config['type']) ? $config['type'] : 'File';
|
$type = isset($config['type']) ? $config['type'] : 'File';
|
||||||
$class = false !== strpos($type, '\\') ? $type : '\\think\\log\\driver\\' . ucwords($type);
|
$class = false !== strpos($type, '\\') ? $type : '\\think\\log\\driver\\' . ucwords($type);
|
||||||
self::$config = $config;
|
self::$config = $config;
|
||||||
unset($config['type']);
|
unset($config['type']);
|
||||||
if(class_exists($class)) {
|
if (class_exists($class)) {
|
||||||
self::$driver = new $class($config);
|
self::$driver = new $class($config);
|
||||||
} else {
|
} else {
|
||||||
throw new ClassNotFoundException('class not exists:' . $class, $class);
|
throw new ClassNotFoundException('class not exists:' . $class, $class);
|
||||||
@@ -62,7 +63,7 @@ class Log
|
|||||||
// 记录初始化信息
|
// 记录初始化信息
|
||||||
App::$debug && Log::record('[ LOG ] INIT ' . $type . ': ' . var_export($config, true), 'info');
|
App::$debug && Log::record('[ LOG ] INIT ' . $type . ': ' . var_export($config, true), 'info');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取日志信息
|
* 获取日志信息
|
||||||
* @param string $type 信息类型
|
* @param string $type 信息类型
|
||||||
@@ -110,7 +111,6 @@ class Log
|
|||||||
*/
|
*/
|
||||||
public static function check($config)
|
public static function check($config)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (self::$key && !empty($config['allow_key']) && !in_array(self::$key, $config['allow_key'])) {
|
if (self::$key && !empty($config['allow_key']) && !in_array(self::$key, $config['allow_key'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user