diff --git a/backend/app/Controller/Api/V1/MqStatusController.php b/backend/app/Controller/Api/V1/MqStatusController.php index c2f3301..b483699 100644 --- a/backend/app/Controller/Api/V1/MqStatusController.php +++ b/backend/app/Controller/Api/V1/MqStatusController.php @@ -8,6 +8,7 @@ use App\Controller\AbstractController; use App\Middleware\AuthMiddleware; use App\Middleware\PermissionMiddleware; use App\Service\MqStatusService; +use App\Utils\Log; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\RequestMapping; @@ -86,9 +87,25 @@ class MqStatusController extends AbstractController 'data' => $data, ]; } catch (\Throwable $e) { + Log::get()->error('MQ status query failed', [ + 'error' => $e->getMessage(), + 'trace' => $e->getTraceAsString(), + ]); + + // 脱敏:mask 异常消息中的敏感信息(IP、端口、认证凭证) + $safe_message = preg_replace( + [ + '/\/\/[^:]+:[^@]+@/', // user:pass@ → //***:***@ + '/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', // IP 地址 + '/:\d{4,5}(?=[\/\s\)]|$)/', // 端口号 + ], + ['//***:***@', '***.***.***.***', ':****'], + $e->getMessage() + ); + return $this->response->json([ 'code' => 500, - 'message' => 'RabbitMQ 连接异常: ' . $e->getMessage(), + 'message' => 'RabbitMQ 连接异常: ' . $safe_message, 'data' => null, ])->withStatus(500); }