Skip to content

Commit

Permalink
Merge pull request #18 from youzan/hotfix/remove_log
Browse files Browse the repository at this point in the history
移除部分框架日志
  • Loading branch information
xu42 authored Apr 15, 2020
2 parents ecb5e8b + ad8ec7d commit 9e9483b
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 28 deletions.
4 changes: 0 additions & 4 deletions src/Daemon/Task/DaemonApolloTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@ class DaemonApolloTask extends BaseComponent

public function handle(): void
{
LogFacade::info("DaemonApolloTask begin...");

/** @var ApolloUtil $apollo */
$apollo = self::getContainer()->get('apolloUtil');
$apollo->writeToFile();

LogFacade::info("DaemonApolloTask end...");
}

}
14 changes: 0 additions & 14 deletions src/Daemon/Task/DaemonTokenTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,30 @@ class DaemonTokenTask extends BaseComponent

public function handle(): void
{
LogFacade::info("DaemonTokenTask begin...");

try {
$this->process();
} catch (Exception $e) {
LogFacade::err("DaemonTokenTask ex..." . $e->getTraceAsString());
}

LogFacade::info("DaemonTokenTask end...");
}

private function process()
{
// 1. 从Apollo拉取KdtId List
$authorityIds = EnvFacade::get('cloud.auth.kdtid');
if (empty($authorityIds)) {
LogFacade::info("DaemonTokenTask process. the authorityIds empty");
return;
}

$authorityIdArr = json_decode($authorityIds, true);
if (!is_array($authorityIdArr)) {
LogFacade::info("DaemonTokenTask process. the authorityIds decode fail. " . $authorityIds);
return;
}

// 2. 遍历 从Redis取值
foreach ($authorityIdArr as $authorityId) {
try {
$key = sprintf(CacheKey::TOKEN, trim($authorityId));
LogFacade::info("DaemonTokenTask process. the key: " . $key);
$this->refreshToken(RedisFacade::get($key));
} catch (Exception $e) {
LogFacade::err("DaemonTokenTask process refreshToken ex. authorityId:{$authorityId}, " . $e->getTraceAsString());
Expand All @@ -56,29 +49,22 @@ private function process()

private function refreshToken($oldTokenStr)
{
LogFacade::info("DaemonTokenTask refreshToken. the oldTokenStr is: " . $oldTokenStr);

if (empty($oldTokenStr) || !is_string($oldTokenStr)) {
LogFacade::info("DaemonTokenTask refreshToken. the oldTokenStr valid. " . $oldTokenStr);
return;
}

$oldTokenArr = json_decode($oldTokenStr, true);
if (!is_array($oldTokenArr) || !array_key_exists('refresh_token', $oldTokenArr)) {
LogFacade::info("DaemonTokenTask refreshToken. the oldTokenStr decode fail. " . $oldTokenStr);
return;
}

$newTokenArr = (new Token(
EnvFacade::get('opensdk.clientId'), EnvFacade::get('opensdk.clientSecret')
))->refreshToken($oldTokenArr['refresh_token']);

LogFacade::info("DaemonTokenTask refreshToken. newTokenArr", $newTokenArr);

if (is_array($newTokenArr) && array_key_exists('access_token', $newTokenArr)) {
$key = sprintf(CacheKey::TOKEN, trim($newTokenArr['authority_id']));
$setResp = RedisFacade::set($key, json_encode($newTokenArr));
LogFacade::info("DaemonTokenTask refreshToken. redis set: {$setResp}", $newTokenArr);
}
}

Expand Down
3 changes: 0 additions & 3 deletions src/Daemon/Worker/IntervalTimerWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class IntervalTimerWorker extends BaseComponent

public function onWorkerStart($worker)
{
LogFacade::info('IntervalTimerWorker.onWorkerStart...');

/** @var IntervalTimerRegistry $intervalTimerRegistry */
$intervalTimerRegistry = $this->getContainer()->get('intervalTimerRegistry');

Expand Down Expand Up @@ -41,7 +39,6 @@ public function onWorkerStart($worker)
continue;
}

LogFacade::info('IntervalTimerWorker.onWorkerStart.' . $name);
Timer::add($timeInterval, $callback, $args, $persistent);
}

Expand Down
1 change: 0 additions & 1 deletion src/Util/ApolloUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ private function pull(string $resource): array
try {
/** @var \YouzanCloudBoot\Http\HttpClientResponse $resp */
$resp = $this->getContainer()->get('httpClient')->get($this->buildHttpUrl($resource), $this->buildHttpHeaders());
LogFacade::info('ApolloUtil pull, http resp: ' . $resp->getBody());
if (empty($resp->getBodyAsJson()) || !isset($resp->getBodyAsJson()['configurations'])) {
return [];
}
Expand Down
7 changes: 1 addition & 6 deletions src/Util/TokenUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,16 @@ public function code2Token(string $code, $reties = 3): array
*/
private function code2TokenProcess(string $code): array
{
LogFacade::info("[code2TokenProcess] code:{$code}");

$tokenArr = (new Token(
EnvFacade::get('opensdk.clientId'), EnvFacade::get('opensdk.clientSecret')
))->getToolAppToken($code);

LogFacade::info("[code2TokenProcess] tokenArr", $tokenArr);

if (!is_array($tokenArr) || !isset($tokenArr['access_token'])) {
throw new TokenException($tokenArr['message'] ?? 'code2Token fail');
}

$key = sprintf(CacheKey::TOKEN, trim($tokenArr['authority_id']));
$setResp = RedisFacade::set($key, json_encode($tokenArr));
LogFacade::info("TokenUtil code2TokenProcess. redis set: {$setResp}", $tokenArr);
RedisFacade::set($key, json_encode($tokenArr));

return $tokenArr;
}
Expand Down

0 comments on commit 9e9483b

Please sign in to comment.