This commit is contained in:
46
app/Log/AliSlsHandler.php
Normal file
46
app/Log/AliSlsHandler.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?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\Amqp\Producer\AliSlsProducer;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\LogRecord;
|
||||
|
||||
/**
|
||||
* Author: ykxiao
|
||||
* Date: 2025/6/3
|
||||
* Time: 下午7:19
|
||||
* 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 AliSlsHandler extends AbstractProcessingHandler
|
||||
{
|
||||
#[Inject]
|
||||
protected Producer $producer;
|
||||
|
||||
protected function write(LogRecord $record): void
|
||||
{
|
||||
$logs = ['channel' => $record['channel'] ?? '', 'formatted' => $record['formatted'] ?? ''];
|
||||
$message = new AliSlsProducer($logs);
|
||||
$this->producer->produce($message, true);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user