# hyperf-aliyun-log **Repository Path**: HfCesar/hyperf-aliyun-log ## Basic Information - **Project Name**: hyperf-aliyun-log - **Description**: hyperf 框架 上传阿里云日志扩展 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-07-09 - **Last Updated**: 2024-06-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # hyperf AliYun SLS Log For Hyperf Copyright (c) 2020 尹萌 Fixed by Ken 2021 肯 Fixed by ceasr 2021 一 安装 composer require hfcesar/hyperf-aliyun-log 二 使用 1. 生成配置文件 php bin/hyperf.php vendor:publish hfcesar/hyperf-aliyun-log 2. 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); 3. getlog 从阿里云 sls use Hyperf\Di\Annotation\Inject; use hfcesar\AliyunSls\ClientInterface; /** * @Inject * @var ClientInterface */ protected $sls; /** * * @param string $project * project name * @param string $logStore * logstore name * @param integer $from * the begin time * @param integer $to * the end time * @param string $topic * topic name of logs * @param string $query * user defined query * @param integer $line * query return line number * @param integer $offset * the log offset to return * @param bool $reverse * if reverse is set to true, the query will return the latest logs first */ $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); }