2017 © Pedro Peláez
 

library aliyun-open-api-sls

The SLS SDK for Aliyun OpenAPI

image

lokielse/aliyun-open-api-sls

The SLS SDK for Aliyun OpenAPI

  • Friday, July 22, 2016
  • by waisir
  • Repository
  • 1 Watchers
  • 1 Stars
  • 1,805 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 10 % Grown

The README.md

The SLS SDK for Aliyun OpenAPI

Latest Version on Packagist ![Software License][ico-license] ![Total Downloads][ico-downloads], (*1)

The SLS SDK for Aliyun OpenAPI, (*2)

Install

Via Composer, (*3)

``` bash $ composer require lokielse/aliyun-open-api-sls, (*4)


## Usage ```php /** * Config */ $config = [ 'AccessKeyId' => 'your_access_key_id', 'AccessKeySecret' => 'your_access_key_secret', 'endpoint' => 'cn-hangzhou.sls.aliyuncs.com', 'project' => 'your_sls_project_name', 'logStore' => 'your_sls_log_store_name', 'topic' => '', 'source' => '', ]; /** * 写日志 (Write Logs) */ $logs = array( new LogItem([ 'user' => 'jello', 'action' => 'trash_photo', 'object_id' => 123456 ]), new LogItem([ 'user' => 'frank', 'action' => 'delete_user', 'object_id' => 100236 ]), ); $putLogsRequest = new PutLogsRequest($config['project'], $config['logStore'], $config['topic'], $config['source'], $logs); $client = new Client($config['endpoint'], $config['AccessKeyId'], $config['AccessKeySecret']); $putLogsResponse = $client->putLogs($putLogsRequest); /** * 读日志 (Read Logs) * 在控制台查看日志有3-5分钟延迟, 但是使用该SDK查看无延迟 */ $listShardRequest = new ListShardsRequest($config['project'], $config['logStore']); $listShardResponse = $client->listShards($listShardRequest); foreach ($listShardResponse->getShardIds() as $shardId) { /** * 对每一个ShardId,先获取Cursor */ $getCursorRequest = new GetCursorRequest($config['project'], $config['logStore'], $shardId, null, time() - 60); $response = $client->getCursor($getCursorRequest); $cursor = $response->getCursor(); $count = 100; while (true) { /** * 从cursor开始读数据 */ $batchGetDataRequest = new BatchGetLogsRequest($config['project'], $config['logStore'], $shardId, $count, $cursor); var_dump($batchGetDataRequest); $response = $client->batchGetLogs($batchGetDataRequest); if ($cursor == $response->getNextCursor()) { break; } $logGroupList = $response->getLogGroupList(); /** * @var \Aliyun\SLS\Log\LogGroup $logGroup * @var Aliyun\SLS\Log\Log $log * @var Aliyun\SLS\Log\LogContent $content */ foreach ($logGroupList as $logGroup) { print ( $logGroup->getCategory() ); foreach ($logGroup->getLogsArray() as $log) { foreach ($log->getContentsArray() as $content) { print( $content->getKey() . ":" . $content->getValue() . "\t" ); } print( "\n" ); } } $cursor = $response->getNextCursor(); } }

官方文档, (*5)

Change log

Please see CHANGELOG for more information what has changed recently., (*6)

Testing

bash $ composer test, (*7)

Contributing

Please see CONTRIBUTING and CONDUCT for details., (*8)

Security

If you discover any security related issues, please email lokielse@gmail.com instead of using the issue tracker., (*9)

Credits

License

The MIT License (MIT). Please see License File for more information., (*10)

The Versions

22/07 2016

dev-master

9999999-dev https://github.com/lokielse/aliyun-open-api-sls

The SLS SDK for Aliyun OpenAPI

  Sources   Download

MIT

The Requires

 

The Development Requires

22/07 2016

v1.0.0

1.0.0.0 https://github.com/lokielse/aliyun-open-api-sls

The SLS SDK for Aliyun OpenAPI

  Sources   Download

MIT

The Requires

 

The Development Requires