diff --git a/extend/think/log/driver/DebugMysql.php b/extend/think/log/driver/DebugMysql.php index e1ee76d..2a3dad6 100644 --- a/extend/think/log/driver/DebugMysql.php +++ b/extend/think/log/driver/DebugMysql.php @@ -75,35 +75,55 @@ class DebugMysql implements LogHandlerInterface $app_name = app('http')->getName() ?: ''; - $controller_name = request()->controller(); - $action_name = request()->action(); + $controller_name = ''; + $action_name = ''; if (App::runningInConsole()) { $app_name = 'cli'; + } else { + + $controller_name = request()->controller(); + $action_name = request()->action(); } $create_time = time(); - $create_time_title = date('Y-m-d H:i:s', $create_time); - $log_key = uniqid(); + $log_key = ''; + + if (defined('REUQEST_UID')) { + $log_key = REUQEST_UID; + } else { + $log_key = uniqid(); + } foreach ($log as $log_level => $log_list) { foreach ($log_list as $key => $log_item) { - if (!is_string($log_item)) { - $log_item = json_encode($log_item, JSON_UNESCAPED_UNICODE); + $log_content = $log_item; + + if ($log_item instanceof \Throwable) { + + $log_content = []; + + $log_content['message'] = $log_item->getMessage(); + $log_content['line'] = $log_item->getLine(); + $log_content['file'] = $log_item->getFile(); + } + + if (!is_string($log_content)) { + $log_content = json_encode($log_content, JSON_UNESCAPED_UNICODE); } $log_data = [ 'level' => $log_level, - 'content' => $log_item, + 'content' => $log_content, 'create_time' => $create_time, 'create_time_title' => $create_time_title, 'uid' => $log_key, 'app_name' => $app_name, 'controller_name' => $controller_name, - 'action_name' => $action_name, + 'action_name' => $action_name ]; if (!is_null($this->pdo)) { diff --git a/public/index.php b/public/index.php index b530391..4e5759f 100644 --- a/public/index.php +++ b/public/index.php @@ -17,7 +17,7 @@ require __DIR__ . '/../vendor/autoload.php'; // 声明全局变量 define('DS', DIRECTORY_SEPARATOR); define('ROOT_PATH', __DIR__ . DS . '..' . DS); - +define('REUQEST_UID', uniqid()); // 执行HTTP应用并响应 $http = (new App())->http;