This commit is contained in:
54
app/Job/RequestWriteLogsJob.php
Normal file
54
app/Job/RequestWriteLogsJob.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Job;
|
||||
|
||||
use App\JsonRpc\EasyAppServiceInterface;
|
||||
use App\Log\Log;
|
||||
use function Hyperf\Support\make;
|
||||
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/6/4
|
||||
* Time: 上午10:23
|
||||
* Description: 请求日志写入任务.
|
||||
*
|
||||
* (c) ykxiao <yk_9001@hotmail.com>
|
||||
*
|
||||
* This source file is subject to the MIT license that is bundled
|
||||
* with this source code in the file LICENSE.
|
||||
*/
|
||||
class RequestWriteLogsJob extends BaseJob
|
||||
{
|
||||
protected function process(): void
|
||||
{
|
||||
$params = $this->data['params']; // 提取请求参数
|
||||
|
||||
// 从参数中删除敏感信息
|
||||
foreach ($params as $key => $value) {
|
||||
if (in_array($key, ['password', 'pwd', 'pwd_conf', 'original_pwd'])) {
|
||||
unset($params[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$rpcResult = make(EasyAppServiceInterface::class)->getClientIPInfo([
|
||||
'ip' => $this->data['client_ip']
|
||||
]);
|
||||
|
||||
$clientIPInfo = $rpcResult['result']['ip_info'] ?? '';
|
||||
|
||||
$logMessage = sprintf('%s %s %s',
|
||||
$this->data['client_ip'] . ' ' . $clientIPInfo,
|
||||
$this->data['method'],
|
||||
$this->data['uri']
|
||||
);
|
||||
if (!empty($params)) {
|
||||
$logMessage .= ' params: ' . json_encode($params, JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
$log = Log::get('request', 'request');
|
||||
$log->info($logMessage);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user