hfcesar / hyperf-aliyun-log
阿里云 SLS Log For Hyperf
v1.0.1
2021-07-09 06:59 UTC
Requires
- php: >=7.2
- hyperf/contract: ^2.0.0
- hyperf/guzzle: ^2.0.0
- psr/container: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.9
- hyperf/config: ^2.0.0
- hyperf/event: ^2.0.0
- hyperf/framework: ^2.0.0
- hyperf/process: ^2.0.0
- malukenho/docheader: ^0.1.6
- mockery/mockery: ^1.0
- phpunit/phpunit: ^7.0.0
This package is auto-updated.
Last update: 2024-09-09 14:15:34 UTC
README
阿里云 SLS Log For Hyperf
版权所有 (c) 2020 尹萌
由 Ken 修复 2021 肯
由 ceasr 修复 2021
一 安装
composer require hfcesar/hyperf-aliyun-log
二 使用
生成配置文件
php bin/hyperf.php vendor:publish hfcesar/hyperf-aliyun-log
putlog 到阿里云 sls
use Hyperf\Di\Annotation\Inject; use hfcesar\AliyunSls\ClientInterface;
/**
- @Inject
- @var ClientInterface */ protected $sls;
// 注意不能有空值,如果有空值可以处理为0,否则无法压缩数据产生致命错误。 $logData = ['k1'=>v1,'k2'=>v2,……];
$this->sls->putLogs($logData);
getlog 从阿里云 sls
use Hyperf\Di\Annotation\Inject; use hfcesar\AliyunSls\ClientInterface;
/**
- @Inject
- @var ClientInterface */ protected $sls;
/** *
- @param string $project
- 项目名称
- @param string $logStore
- 日志存储名称
- @param integer $from
- 起始时间
- @param integer $to
- 结束时间
- @param string $topic
- 日志主题名称
- @param string $query
- 用户自定义查询
- @param integer $line
- 查询返回的行数
- @param integer $offset
- 要返回的日志偏移量
- @param bool $reverse
- 如果 reverse 设置为 true,则查询将首先返回最新的日志 */
$response = $this->sls->getLogs($project, $logstore, $from, $to, $topic, $query, $line, $offset, $reverse); if ($response->getCount()[0] > 0) {
foreach($response->getLogs() as $log){ $datas[] = $log->getContents(); } print_r($datas);
}