51 lines
1.2 KiB
PHP
51 lines
1.2 KiB
PHP
<?php
|
|
/**
|
|
* Author: ykxiao
|
|
* Date: 2025/6/3
|
|
* Time: 下午6:33
|
|
* 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.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Log;
|
|
|
|
use App\Context\ApiUrlContext;
|
|
use Hyperf\Context\Context;
|
|
use Hyperf\Coroutine\Coroutine;
|
|
use Monolog\LogRecord;
|
|
use Monolog\Processor\ProcessorInterface;
|
|
|
|
/**
|
|
* Author: ykxiao
|
|
* Date: 2025/6/3
|
|
* Time: 下午7:19
|
|
* Description: 添加请求ID和协程ID
|
|
*
|
|
* (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 AppendRequestIdProcessor implements ProcessorInterface
|
|
{
|
|
public const string REQUEST_ID = 'log.request.id';
|
|
|
|
public function __invoke(LogRecord $record): array|LogRecord
|
|
{
|
|
$contextData = ApiUrlContext::getApiUrl();
|
|
|
|
if ($contextData) {
|
|
$record['extra']['api_url'] = $contextData;
|
|
}
|
|
|
|
$record['extra']['request_id'] = Context::getOrSet(self::REQUEST_ID, uniqid('xw_cloud'));
|
|
$record['extra']['coroutine_id'] = Coroutine::id();
|
|
return $record;
|
|
}
|
|
} |