setName('api_log')->setDescription('the api_log command'); } protected function execute(Input $input, Output $output) { try { $redis = Cache::store('redis')->handler(); $result = $redis->blpop(['api_log'], 5); if ($result) { $logData = json_decode($result[1], true); if (!is_array($logData) || empty($logData)) { return; } $logData['params'] = json_encode($logData['params'] ?? [], JSON_UNESCAPED_UNICODE); $logData['response'] = json_encode($logData['response'] ?? [], JSON_UNESCAPED_UNICODE); try { ApiLogModel::create($logData); } catch (\Throwable $e) { $redis->lpush('api_log', $result[1]); throw $e; } } else { return; } } catch (\Throwable $e) { Log::error('ApiLogCommand error: ' . $e->getMessage()); } return; } }