From aeb3b28184e8e8ab010a8eca60a938cfc8b2e7c6 Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Fri, 20 Sep 2024 09:49:26 +0800 Subject: [PATCH] fix(SystemLog): limit response content in admin middleware Implement a limitation on the amount of response content recorded in the system logs to avoid excessively large entries. The response is now truncated to 3000 characters, enhancing performance and readability while still capturing essential data. --- app/admin/middleware/SystemLog.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/admin/middleware/SystemLog.php b/app/admin/middleware/SystemLog.php index 91b07fe..13dc381 100644 --- a/app/admin/middleware/SystemLog.php +++ b/app/admin/middleware/SystemLog.php @@ -63,7 +63,12 @@ class SystemLog } }catch (\Throwable $exception) { } - $ip = $request->ip(); + + $ip = $request->ip(); + // 限制记录的响应内容,避免过大 + $response = json_encode($response->getData(), JSON_UNESCAPED_UNICODE); + $response = mb_substr($response, 0, 3000, 'utf-8'); + $data = [ 'admin_id' => session('admin.id'), 'title' => $title, @@ -71,7 +76,7 @@ class SystemLog 'method' => $method, 'ip' => $ip, 'content' => json_encode($params, JSON_UNESCAPED_UNICODE), - 'response' => json_encode($response->getData(), JSON_UNESCAPED_UNICODE), + 'response' => $response, 'useragent' => $request->server('HTTP_USER_AGENT'), 'create_time' => time(), ];