Commit 92b52cfa authored by Euan游根明's avatar Euan游根明

perf: 日志

parent bc314265
...@@ -55,7 +55,7 @@ class Nacos ...@@ -55,7 +55,7 @@ class Nacos
} }
self::info($logs); self::info($logs);
} catch (\Exception $e) { } catch (\Exception $e) {
self::info(['msg'=>'获取配置失败'. $key.':'.$e->getMessage(),'ex'=> $e]); self::info(['msg'=>'获取配置失败'. $key.':'.$e->getMessage(),'ex'=>$e->getTraceAsString()]);
} }
} }
...@@ -135,34 +135,39 @@ class Nacos ...@@ -135,34 +135,39 @@ class Nacos
* @return mixed|string * @return mixed|string
*/ */
public static function getConfigRequest($url){ public static function getConfigRequest($url){
// 创建一个cURL资源 try {
$curl = curl_init(); // 创建一个cURL资源
curl_setopt_array($curl, array( $curl = curl_init();
CURLOPT_URL => $url, curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $url,
CURLOPT_MAXREDIRS => 10, CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30, CURLOPT_MAXREDIRS => 10,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_TIMEOUT => 30,
CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_HTTPHEADER => array( CURLOPT_CUSTOMREQUEST => "GET",
"Content-Type: application/json", CURLOPT_HTTPHEADER => array(
"Access-Type: application/json", "Content-Type: application/json",
"cache-control: no-cache" "Access-Type: application/json",
), "cache-control: no-cache"
)); ),
$response = curl_exec($curl); ));
$err = curl_error($curl); $response = curl_exec($curl);
if ($err){ $err = curl_error($curl);
self::info($err); if ($err){
} self::info($err);
curl_close($curl); }
$data = json_decode($response,true); curl_close($curl);
if (isset($data['status']) && $data['status'] == 403){ $data = json_decode($response,true);
throw new \Exception('token过期',403); if (isset($data['status']) && $data['status'] == 403){
} throw new \Exception('token过期',403);
if (isset($data['code']) && $data['code'] !== 0){ }
self::info('获取配置返回结果:'.$response); if (isset($data['code']) && $data['code'] !== 0){
return ''; self::info('获取配置返回结果:'.$response);
return '';
}
return $data['data'] ?? '';
} catch (\Exception $e) {
self::info(['msg'=>$e->getMessage(),'ex'=>$e->getTraceAsString()]);
} }
return $data['data'] ?? ''; return $data['data'] ?? '';
} }
...@@ -201,7 +206,7 @@ class Nacos ...@@ -201,7 +206,7 @@ class Nacos
$loginDataArr = json_decode($response,true); $loginDataArr = json_decode($response,true);
return $loginDataArr['accessToken'] ?? ''; return $loginDataArr['accessToken'] ?? '';
} catch (\Exception $e) { } catch (\Exception $e) {
self::info($e->getMessage()); self::info(['msg'=>$e->getMessage(),'ex'=>$e->getTraceAsString()]);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment