Skip to content

Commit

Permalink
Merge pull request #139 from wonder-game/develop
Browse files Browse the repository at this point in the history
feat: 优化request的日志记录
  • Loading branch information
linkunyuan authored Dec 23, 2024
2 parents 6d2c5c8 + 3b4de52 commit 0eaeb80
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Common/Classes/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function request($type, $url = '', $data = [], $method = 'post', $header
},
'retryTimes' => 3,
'curt' => 0,
'keyword' => '', // 日志的特征关键字,方便查错
'trace' => ['level' => 'error', 'category' => 'debug'], // 日志参数
];
$cfg = array_merge($defaults, $cfg);

Expand All @@ -50,8 +52,8 @@ public function request($type, $url = '', $data = [], $method = 'post', $header
}
$response = $this->$sendType($url, $data, $method, $header, $option);
} catch (Exception $e) {
$err = "{$url}请求失败!信息为:{$e->getMessage()} 传参为:" . json_encode(func_get_args());
trace($err, 'error');
$err = "{$cfg['keyword']} {$url}请求失败!信息为:{$e->getMessage()} 传参为:" . json_encode(func_get_args());
trace($err, $cfg['trace']['level'], $cfg['trace']['category']);
throw new Exception($err, $e->getCode());
}

Expand Down Expand Up @@ -89,8 +91,8 @@ public function request($type, $url = '', $data = [], $method = 'post', $header
Coroutine::sleep(0.5);
return $this->request($type, $url, $data, $method, $header, ['curt' => ++$cfg['curt']] + $cfg, $option);
}
$err = "{$url}响应失败!状态码为:$code,响应内容为:$org, 传参为:" . json_encode(func_get_args());
trace($err, 'error');
$err = "{$cfg['keyword']} {$url}响应失败!状态码为:$code,响应内容为:$org, 传参为:" . json_encode(func_get_args());
trace($err, $cfg['trace']['level'], $cfg['trace']['category']);
throw new Exception($err);
}

Expand Down

0 comments on commit 0eaeb80

Please sign in to comment.