|
@ -40,8 +40,14 @@ class ApiLogMiddleware |
|
|
if ($request->method(true) === 'OPTIONS') { |
|
|
if ($request->method(true) === 'OPTIONS') { |
|
|
return response()->send(); |
|
|
return response()->send(); |
|
|
} |
|
|
} |
|
|
|
|
|
$response = $next($request); |
|
|
$path = $request->pathinfo(); |
|
|
$path = $request->pathinfo(); |
|
|
$shouldLog = in_array($path, $this->logRoutes); |
|
|
$shouldLog = in_array($path, $this->logRoutes); |
|
|
|
|
|
$responseData = $response instanceof Response ? $response->getData() : null; |
|
|
|
|
|
// 如果接口返回错误码,也记录日志 |
|
|
|
|
|
if ($responseData && isset($responseData['code']) && $responseData['code'] != 0) { |
|
|
|
|
|
$shouldLog = true; |
|
|
|
|
|
} |
|
|
$logData = []; |
|
|
$logData = []; |
|
|
if ($shouldLog) { |
|
|
if ($shouldLog) { |
|
|
$ip = (new BaseHomeService())->getClientRealIp(); |
|
|
$ip = (new BaseHomeService())->getClientRealIp(); |
|
@ -58,11 +64,9 @@ class ApiLogMiddleware |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$response = $next($request); |
|
|
|
|
|
|
|
|
|
|
|
if ($shouldLog && $response instanceof Response) { |
|
|
if ($shouldLog && $response instanceof Response) { |
|
|
|
|
|
|
|
|
$logData['response'] = $response->getData(); |
|
|
$logData['response'] = $responseData; |
|
|
} |
|
|
} |
|
|
//写入redis |
|
|
//写入redis |
|
|
if (!empty($logData)) { |
|
|
if (!empty($logData)) { |
|
|