From 8b0a8cb3c90b7e8ad01af3dc58d86dcfb14f560b Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Wed, 20 Dec 2017 13:50:59 +0800 Subject: [PATCH 01/19] =?UTF-8?q?sdk=E6=BA=90=E6=96=87=E4=BB=B6=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E8=B0=83=E6=95=B4=EF=BC=8C=E5=A2=9E=E5=8A=A0logger?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aliyun/Log/Logger.php | 54 ++ .../ApplyConfigToMachineGroupRequest.php | 78 +-- .../{ => Request}/BatchGetLogsRequest.php | 268 +++++----- .../Models/{ => Request}/CreateACLRequest.php | 64 +-- .../{ => Request}/CreateConfigRequest.php | 70 +-- .../{ => Request}/CreateLogstoreRequest.php | 84 +-- .../CreateMachineGroupRequest.php | 62 +-- .../Models/{ => Request}/DeleteACLRequest.php | 62 +-- .../{ => Request}/DeleteConfigRequest.php | 66 +-- .../{ => Request}/DeleteLogstoreRequest.php | 60 +-- .../DeleteMachineGroupRequest.php | 68 +-- .../{ => Request}/DeleteShardRequest.php | 78 +-- .../Models/{ => Request}/GetACLRequest.php | 60 +-- .../Models/{ => Request}/GetConfigRequest.php | 68 +-- .../Models/{ => Request}/GetCursorRequest.php | 276 +++++----- .../{ => Request}/GetHistogramsRequest.php | 322 ++++++------ .../Models/{ => Request}/GetLogsRequest.php | 484 +++++++++--------- .../{ => Request}/GetMachineGroupRequest.php | 62 +-- .../{ => Request}/GetMachineRequest.php | 68 +-- .../Models/{ => Request}/ListACLsRequest.php | 102 ++-- .../{ => Request}/ListConfigsRequest.php | 108 ++-- .../{ => Request}/ListLogstoresRequest.php | 48 +- .../ListMachineGroupsRequest.php | 106 ++-- .../{ => Request}/ListShardsRequest.php | 72 +-- .../{ => Request}/ListTopicsRequest.php | 204 ++++---- .../{ => Request}/MergeShardsRequest.php | 78 +-- .../Models/{ => Request}/PutLogsRequest.php | 312 +++++------ .../RemoveConfigFromMachineGroupRequest.php | 80 +-- Aliyun/Log/Models/{ => Request}/Request.php | 94 ++-- .../{ => Request}/SplitShardRequest.php | 88 ++-- .../Models/{ => Request}/UpdateACLRequest.php | 62 +-- .../{ => Request}/UpdateConfigRequest.php | 66 +-- .../{ => Request}/UpdateLogstoreRequest.php | 84 +-- .../UpdateMachineGroupRequest.php | 68 +-- .../ApplyConfigToMachineGroupResponse.php | 58 +-- .../{ => Response}/BatchGetLogsResponse.php | 146 +++--- .../{ => Response}/CreateACLResponse.php | 66 +-- .../{ => Response}/CreateConfigResponse.php | 58 +-- .../{ => Response}/CreateLogstoreResponse.php | 56 +- .../CreateMachineGroupResponse.php | 58 +-- .../{ => Response}/DeleteACLResponse.php | 58 +-- .../{ => Response}/DeleteConfigResponse.php | 56 +- .../{ => Response}/DeleteLogstoreResponse.php | 56 +- .../DeleteMachineGroupResponse.php | 58 +-- .../{ => Response}/DeleteShardResponse.php | 48 +- .../Models/{ => Response}/GetACLResponse.php | 80 +-- .../{ => Response}/GetConfigResponse.php | 74 +-- .../{ => Response}/GetCursorResponse.php | 82 +-- .../{ => Response}/GetHistogramsResponse.php | 154 +++--- .../Models/{ => Response}/GetLogsResponse.php | 162 +++--- .../GetMachineGroupResponse.php | 72 +-- .../{ => Response}/GetMachineResponse.php | 76 +-- .../{ => Response}/ListACLsResponse.php | 88 ++-- .../{ => Response}/ListConfigsResponse.php | 88 ++-- .../{ => Response}/ListLogstoresResponse.php | 114 ++--- .../ListMachineGroupsResponse.php | 90 ++-- .../{ => Response}/ListShardsResponse.php | 86 ++-- .../{ => Response}/ListTopicsResponse.php | 146 +++--- .../Models/{ => Response}/PutLogsResponse.php | 48 +- .../RemoveConfigFromMachineGroupResponse.php | 56 +- Aliyun/Log/Models/{ => Response}/Response.php | 116 ++--- Aliyun/Log/Models/{ => Response}/Shard.php | 0 .../{ => Response}/UpdateACLResponse.php | 58 +-- .../{ => Response}/UpdateConfigResponse.php | 58 +-- .../{ => Response}/UpdateLogstoreResponse.php | 56 +- .../UpdateMachineGroupResponse.php | 58 +-- Aliyun/Log/Models/logLevel/LogLevel.php | 42 ++ Aliyun/Log/protocolbuffers.inc.php | 32 +- Log_Autoload.php | 16 +- sample/demo.php | 86 ++++ sample/sample.php | 82 +-- 71 files changed, 3435 insertions(+), 3229 deletions(-) create mode 100644 Aliyun/Log/Logger.php rename Aliyun/Log/Models/{ => Request}/ApplyConfigToMachineGroupRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/BatchGetLogsRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/CreateACLRequest.php (94%) rename Aliyun/Log/Models/{ => Request}/CreateConfigRequest.php (94%) rename Aliyun/Log/Models/{ => Request}/CreateLogstoreRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/CreateMachineGroupRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/DeleteACLRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/DeleteConfigRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/DeleteLogstoreRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/DeleteMachineGroupRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/DeleteShardRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/GetACLRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/GetConfigRequest.php (94%) rename Aliyun/Log/Models/{ => Request}/GetCursorRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/GetHistogramsRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/GetLogsRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/GetMachineGroupRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/GetMachineRequest.php (94%) rename Aliyun/Log/Models/{ => Request}/ListACLsRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/ListConfigsRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/ListLogstoresRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/ListMachineGroupsRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/ListShardsRequest.php (94%) rename Aliyun/Log/Models/{ => Request}/ListTopicsRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/MergeShardsRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/PutLogsRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/RemoveConfigFromMachineGroupRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/Request.php (94%) rename Aliyun/Log/Models/{ => Request}/SplitShardRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/UpdateACLRequest.php (94%) rename Aliyun/Log/Models/{ => Request}/UpdateConfigRequest.php (94%) rename Aliyun/Log/Models/{ => Request}/UpdateLogstoreRequest.php (95%) rename Aliyun/Log/Models/{ => Request}/UpdateMachineGroupRequest.php (95%) rename Aliyun/Log/Models/{ => Response}/ApplyConfigToMachineGroupResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/BatchGetLogsResponse.php (96%) rename Aliyun/Log/Models/{ => Response}/CreateACLResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/CreateConfigResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/CreateLogstoreResponse.php (96%) rename Aliyun/Log/Models/{ => Response}/CreateMachineGroupResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/DeleteACLResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/DeleteConfigResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/DeleteLogstoreResponse.php (96%) rename Aliyun/Log/Models/{ => Response}/DeleteMachineGroupResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/DeleteShardResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/GetACLResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/GetConfigResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/GetCursorResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/GetHistogramsResponse.php (96%) rename Aliyun/Log/Models/{ => Response}/GetLogsResponse.php (96%) rename Aliyun/Log/Models/{ => Response}/GetMachineGroupResponse.php (96%) rename Aliyun/Log/Models/{ => Response}/GetMachineResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/ListACLsResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/ListConfigsResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/ListLogstoresResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/ListMachineGroupsResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/ListShardsResponse.php (93%) rename Aliyun/Log/Models/{ => Response}/ListTopicsResponse.php (96%) rename Aliyun/Log/Models/{ => Response}/PutLogsResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/RemoveConfigFromMachineGroupResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/Response.php (95%) rename Aliyun/Log/Models/{ => Response}/Shard.php (100%) rename Aliyun/Log/Models/{ => Response}/UpdateACLResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/UpdateConfigResponse.php (95%) rename Aliyun/Log/Models/{ => Response}/UpdateLogstoreResponse.php (96%) rename Aliyun/Log/Models/{ => Response}/UpdateMachineGroupResponse.php (95%) create mode 100644 Aliyun/Log/Models/logLevel/LogLevel.php create mode 100644 sample/demo.php diff --git a/Aliyun/Log/Logger.php b/Aliyun/Log/Logger.php new file mode 100644 index 0000000..d4f94ac --- /dev/null +++ b/Aliyun/Log/Logger.php @@ -0,0 +1,54 @@ +client = $client; + $this->logstore=$logstore; + $this->project=$project; + } + + + private function getLocalIp(){ + $local_ip = getHostByName(php_uname('n')); + if(strlen($local_ip) == 0){ + $local_ip = getHostByName(getHostName()); + } + return $local_ip; + } + + public function log($logLevel, $logMessage, $topic){ + $ip = $this->getLocalIp(); + $contents = array( // key-value pair + 'time'=>date('m/d/Y h:i:s a', time()), + 'message'=> $logMessage, + 'loglevel'=> $logLevel + ); + try { + $logItem = new Aliyun_Log_Models_LogItem(); + $logItem->setTime(time()); + $logItem->setContents($contents); + $logitems = array($logItem); + $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, + $topic, $ip, $logitems); + $response = $this->client->putLogs($request); + print($response ->getRequestId()); + } catch (Aliyun_Log_Exception $ex) { + logVarDump($ex); + } catch (Exception $ex) { + logVarDump($ex); + } + } + +} \ No newline at end of file diff --git a/Aliyun/Log/Models/ApplyConfigToMachineGroupRequest.php b/Aliyun/Log/Models/Request/ApplyConfigToMachineGroupRequest.php similarity index 95% rename from Aliyun/Log/Models/ApplyConfigToMachineGroupRequest.php rename to Aliyun/Log/Models/Request/ApplyConfigToMachineGroupRequest.php index 0788973..28291ca 100644 --- a/Aliyun/Log/Models/ApplyConfigToMachineGroupRequest.php +++ b/Aliyun/Log/Models/Request/ApplyConfigToMachineGroupRequest.php @@ -1,39 +1,39 @@ -groupName = $groupName; - $this->configName = $configName; - } - public function getGroupName(){ - return $this->groupName; - } - public function setGroupName($groupName){ - $this->groupName = $groupName; - } - - public function getConfigName(){ - return $this->configName; - } - public function setConfigName($configName){ - $this->configName = $configName; - } - -} +groupName = $groupName; + $this->configName = $configName; + } + public function getGroupName(){ + return $this->groupName; + } + public function setGroupName($groupName){ + $this->groupName = $groupName; + } + + public function getConfigName(){ + return $this->configName; + } + public function setConfigName($configName){ + $this->configName = $configName; + } + +} diff --git a/Aliyun/Log/Models/BatchGetLogsRequest.php b/Aliyun/Log/Models/Request/BatchGetLogsRequest.php similarity index 95% rename from Aliyun/Log/Models/BatchGetLogsRequest.php rename to Aliyun/Log/Models/Request/BatchGetLogsRequest.php index 0df9582..1ea6234 100644 --- a/Aliyun/Log/Models/BatchGetLogsRequest.php +++ b/Aliyun/Log/Models/Request/BatchGetLogsRequest.php @@ -1,134 +1,134 @@ -logstore = $logstore; - $this->shardId = $shardId; - $this->count = $count; - $this->cursor = $cursor; - } - - /** - * Get logstore name - * - * @return string logstore name - */ - public function getLogstore() { - return $this->logstore; - } - - /** - * Set logstore name - * - * @param string $logstore - * logstore name - */ - public function setLogstore($logstore) { - $this->logstore = $logstore; - } - - /** - * Get shard ID - * - * @return string shardId - */ - public function getShardId() { - return $this->shardId; - } - - /** - * Set shard ID - * - * @param string $shardId - * shard ID - */ - public function setShardId($shardId) { - $this->shardId = $shardId; - } - - /** - * Get max return loggroup number - * - * @return integer count - */ - public function getCount() { - return $this->count; - } - - /** - * Set max return loggroup number - * - * @param integer $count - * max return loggroup number - */ - public function setCount($count) { - $this->count = $count; - } - - /** - * Get start cursor - * - * @return string cursor - */ - public function getCursor() { - return $this->cursor; - } - - /** - * Set start cursor - * - * @param string $cursor - * start cursor - */ - public function setCursor($cursor) { - $this->cursor = $cursor; - } - -} +logstore = $logstore; + $this->shardId = $shardId; + $this->count = $count; + $this->cursor = $cursor; + } + + /** + * Get logstore name + * + * @return string logstore name + */ + public function getLogstore() { + return $this->logstore; + } + + /** + * Set logstore name + * + * @param string $logstore + * logstore name + */ + public function setLogstore($logstore) { + $this->logstore = $logstore; + } + + /** + * Get shard ID + * + * @return string shardId + */ + public function getShardId() { + return $this->shardId; + } + + /** + * Set shard ID + * + * @param string $shardId + * shard ID + */ + public function setShardId($shardId) { + $this->shardId = $shardId; + } + + /** + * Get max return loggroup number + * + * @return integer count + */ + public function getCount() { + return $this->count; + } + + /** + * Set max return loggroup number + * + * @param integer $count + * max return loggroup number + */ + public function setCount($count) { + $this->count = $count; + } + + /** + * Get start cursor + * + * @return string cursor + */ + public function getCursor() { + return $this->cursor; + } + + /** + * Set start cursor + * + * @param string $cursor + * start cursor + */ + public function setCursor($cursor) { + $this->cursor = $cursor; + } + +} diff --git a/Aliyun/Log/Models/CreateACLRequest.php b/Aliyun/Log/Models/Request/CreateACLRequest.php similarity index 94% rename from Aliyun/Log/Models/CreateACLRequest.php rename to Aliyun/Log/Models/Request/CreateACLRequest.php index 01558f5..7b0892c 100644 --- a/Aliyun/Log/Models/CreateACLRequest.php +++ b/Aliyun/Log/Models/Request/CreateACLRequest.php @@ -1,32 +1,32 @@ -acl = $acl; - } - - public function getAcl(){ - return $this->acl; - } - public function setAcl($acl){ - $this->acl = $acl; - } - -} +acl = $acl; + } + + public function getAcl(){ + return $this->acl; + } + public function setAcl($acl){ + $this->acl = $acl; + } + +} diff --git a/Aliyun/Log/Models/CreateConfigRequest.php b/Aliyun/Log/Models/Request/CreateConfigRequest.php similarity index 94% rename from Aliyun/Log/Models/CreateConfigRequest.php rename to Aliyun/Log/Models/Request/CreateConfigRequest.php index 636188b..5ad80ca 100644 --- a/Aliyun/Log/Models/CreateConfigRequest.php +++ b/Aliyun/Log/Models/Request/CreateConfigRequest.php @@ -1,35 +1,35 @@ -config = $config; - } - - public function getConfig(){ - return $this->config; - - } - - public function setConfig($config){ - $this->config = $config; - } - -} +config = $config; + } + + public function getConfig(){ + return $this->config; + + } + + public function setConfig($config){ + $this->config = $config; + } + +} diff --git a/Aliyun/Log/Models/CreateLogstoreRequest.php b/Aliyun/Log/Models/Request/CreateLogstoreRequest.php similarity index 95% rename from Aliyun/Log/Models/CreateLogstoreRequest.php rename to Aliyun/Log/Models/Request/CreateLogstoreRequest.php index ac2e625..0fc6670 100644 --- a/Aliyun/Log/Models/CreateLogstoreRequest.php +++ b/Aliyun/Log/Models/Request/CreateLogstoreRequest.php @@ -1,42 +1,42 @@ - logstore = $logstore; - $this -> ttl = $ttl; - $this -> shardCount = $shardCount; - } - public function getLogstore() - { - return $this -> logstore; - } - public function getTtl() - { - return $this -> ttl; - } - public function getShardCount() - { - return $this -> shardCount; - } -} + logstore = $logstore; + $this -> ttl = $ttl; + $this -> shardCount = $shardCount; + } + public function getLogstore() + { + return $this -> logstore; + } + public function getTtl() + { + return $this -> ttl; + } + public function getShardCount() + { + return $this -> shardCount; + } +} diff --git a/Aliyun/Log/Models/CreateMachineGroupRequest.php b/Aliyun/Log/Models/Request/CreateMachineGroupRequest.php similarity index 95% rename from Aliyun/Log/Models/CreateMachineGroupRequest.php rename to Aliyun/Log/Models/Request/CreateMachineGroupRequest.php index 41166c8..6f707c9 100644 --- a/Aliyun/Log/Models/CreateMachineGroupRequest.php +++ b/Aliyun/Log/Models/Request/CreateMachineGroupRequest.php @@ -1,31 +1,31 @@ -machineGroup = $machineGroup; - } - public function getMachineGroup(){ - return $this->machineGroup; - } - public function setMachineGroup($machineGroup){ - $this->machineGroup = $machineGroup; - } - -} +machineGroup = $machineGroup; + } + public function getMachineGroup(){ + return $this->machineGroup; + } + public function setMachineGroup($machineGroup){ + $this->machineGroup = $machineGroup; + } + +} diff --git a/Aliyun/Log/Models/DeleteACLRequest.php b/Aliyun/Log/Models/Request/DeleteACLRequest.php similarity index 95% rename from Aliyun/Log/Models/DeleteACLRequest.php rename to Aliyun/Log/Models/Request/DeleteACLRequest.php index a6a2ba8..2006c90 100644 --- a/Aliyun/Log/Models/DeleteACLRequest.php +++ b/Aliyun/Log/Models/Request/DeleteACLRequest.php @@ -1,31 +1,31 @@ -aclId = $aclId; - } - public function getAclId(){ - return $this->aclId; - } - public function setAclId($aclId){ - $this->aclId = $aclId; - } - -} +aclId = $aclId; + } + public function getAclId(){ + return $this->aclId; + } + public function setAclId($aclId){ + $this->aclId = $aclId; + } + +} diff --git a/Aliyun/Log/Models/DeleteConfigRequest.php b/Aliyun/Log/Models/Request/DeleteConfigRequest.php similarity index 95% rename from Aliyun/Log/Models/DeleteConfigRequest.php rename to Aliyun/Log/Models/Request/DeleteConfigRequest.php index 5d435ae..3afc9ec 100644 --- a/Aliyun/Log/Models/DeleteConfigRequest.php +++ b/Aliyun/Log/Models/Request/DeleteConfigRequest.php @@ -1,33 +1,33 @@ -configName = $configName; - } - - public function getConfigName(){ - return $this->configName; - } - - public function setConfigName($configName){ - $this->configName=$configName; - } - -} +configName = $configName; + } + + public function getConfigName(){ + return $this->configName; + } + + public function setConfigName($configName){ + $this->configName=$configName; + } + +} diff --git a/Aliyun/Log/Models/DeleteLogstoreRequest.php b/Aliyun/Log/Models/Request/DeleteLogstoreRequest.php similarity index 95% rename from Aliyun/Log/Models/DeleteLogstoreRequest.php rename to Aliyun/Log/Models/Request/DeleteLogstoreRequest.php index e587fbb..8c0d39f 100644 --- a/Aliyun/Log/Models/DeleteLogstoreRequest.php +++ b/Aliyun/Log/Models/Request/DeleteLogstoreRequest.php @@ -1,30 +1,30 @@ - logstore = $logstore; - } - public function getLogstore() - { - return $this -> logstore; - } -} + logstore = $logstore; + } + public function getLogstore() + { + return $this -> logstore; + } +} diff --git a/Aliyun/Log/Models/DeleteMachineGroupRequest.php b/Aliyun/Log/Models/Request/DeleteMachineGroupRequest.php similarity index 95% rename from Aliyun/Log/Models/DeleteMachineGroupRequest.php rename to Aliyun/Log/Models/Request/DeleteMachineGroupRequest.php index d0ef8c0..a04367b 100644 --- a/Aliyun/Log/Models/DeleteMachineGroupRequest.php +++ b/Aliyun/Log/Models/Request/DeleteMachineGroupRequest.php @@ -1,34 +1,34 @@ -groupName = $groupName; - } - - public function getGroupName(){ - return $this->groupName; - } - - public function setGroupName($groupName){ - $this->groupName = $groupName; - } - -} +groupName = $groupName; + } + + public function getGroupName(){ + return $this->groupName; + } + + public function setGroupName($groupName){ + $this->groupName = $groupName; + } + +} diff --git a/Aliyun/Log/Models/DeleteShardRequest.php b/Aliyun/Log/Models/Request/DeleteShardRequest.php similarity index 95% rename from Aliyun/Log/Models/DeleteShardRequest.php rename to Aliyun/Log/Models/Request/DeleteShardRequest.php index 3b9aeb9..e45a371 100644 --- a/Aliyun/Log/Models/DeleteShardRequest.php +++ b/Aliyun/Log/Models/Request/DeleteShardRequest.php @@ -1,39 +1,39 @@ -logstore = $logstore; - $this->shardId = $shardId; - } - - public function getLogstore(){ - return $this->logstore; - } - - public function setLogstore($logstore){ - $this->logstore = $logstore; - } - - public function getShardId(){ - return $this->shardId; - } -} +logstore = $logstore; + $this->shardId = $shardId; + } + + public function getLogstore(){ + return $this->logstore; + } + + public function setLogstore($logstore){ + $this->logstore = $logstore; + } + + public function getShardId(){ + return $this->shardId; + } +} diff --git a/Aliyun/Log/Models/GetACLRequest.php b/Aliyun/Log/Models/Request/GetACLRequest.php similarity index 95% rename from Aliyun/Log/Models/GetACLRequest.php rename to Aliyun/Log/Models/Request/GetACLRequest.php index af16670..ce9690a 100644 --- a/Aliyun/Log/Models/GetACLRequest.php +++ b/Aliyun/Log/Models/Request/GetACLRequest.php @@ -1,30 +1,30 @@ -aclId = $aclId; - } - public function getAclId(){ - return $this->aclId; - } - public function setAclId($aclId){ - $this->aclId = $aclId; - } -} +aclId = $aclId; + } + public function getAclId(){ + return $this->aclId; + } + public function setAclId($aclId){ + $this->aclId = $aclId; + } +} diff --git a/Aliyun/Log/Models/GetConfigRequest.php b/Aliyun/Log/Models/Request/GetConfigRequest.php similarity index 94% rename from Aliyun/Log/Models/GetConfigRequest.php rename to Aliyun/Log/Models/Request/GetConfigRequest.php index 7dc2bf5..78a15d2 100644 --- a/Aliyun/Log/Models/GetConfigRequest.php +++ b/Aliyun/Log/Models/Request/GetConfigRequest.php @@ -1,34 +1,34 @@ -configName = $configName; - } - - public function getConfigName(){ - return $this->configName; - } - - public function setConfigName($configName){ - $this->configName = $configName; - } - -} +configName = $configName; + } + + public function getConfigName(){ + return $this->configName; + } + + public function setConfigName($configName){ + $this->configName = $configName; + } + +} diff --git a/Aliyun/Log/Models/GetCursorRequest.php b/Aliyun/Log/Models/Request/GetCursorRequest.php similarity index 95% rename from Aliyun/Log/Models/GetCursorRequest.php rename to Aliyun/Log/Models/Request/GetCursorRequest.php index 636209a..933b2e8 100644 --- a/Aliyun/Log/Models/GetCursorRequest.php +++ b/Aliyun/Log/Models/Request/GetCursorRequest.php @@ -1,138 +1,138 @@ -logstore = $logstore; - $this->shardId = $shardId; - $this->mode = $mode; - $this->fromTime = $fromTime; - } - - /** - * Get logstore name - * - * @return string logstore name - */ - public function getLogstore(){ - return $this->logstore; - } - - /** - * Set logstore name - * - * @param string $logstore - * logstore name - */ - public function setLogstore($logstore){ - $this->logstore = $logstore; - } - - /** - * Get shard id - * - * @return string shard id - */ - public function getShardId(){ - return $this->shardId; - } - - /** - * Set shard id - * - * @param string $shardId - * shard id - */ - public function setShardId($shardId){ - $this->shardId = $shardId; - } - - /** - * Get mode - * - * @return string mode - */ - public function getMode(){ - return $this->mode; - } - - /** - * Set mode - * - * @param string $mode - * value must be 'begin' or 'end' - */ - public function setMode($mode){ - $this->mode = $mode; - } - - /** - * Get from time - * - * @return integer(unix_timestamp) from time - */ - public function getFromTime(){ - return $this->fromTime; - } - - /** - * Set from time - * - * @param integer $fromTime - * from time (unix_timestamp) - */ - public function setFromTime($fromTime){ - $this->fromTime = $fromTime; - } - -} +logstore = $logstore; + $this->shardId = $shardId; + $this->mode = $mode; + $this->fromTime = $fromTime; + } + + /** + * Get logstore name + * + * @return string logstore name + */ + public function getLogstore(){ + return $this->logstore; + } + + /** + * Set logstore name + * + * @param string $logstore + * logstore name + */ + public function setLogstore($logstore){ + $this->logstore = $logstore; + } + + /** + * Get shard id + * + * @return string shard id + */ + public function getShardId(){ + return $this->shardId; + } + + /** + * Set shard id + * + * @param string $shardId + * shard id + */ + public function setShardId($shardId){ + $this->shardId = $shardId; + } + + /** + * Get mode + * + * @return string mode + */ + public function getMode(){ + return $this->mode; + } + + /** + * Set mode + * + * @param string $mode + * value must be 'begin' or 'end' + */ + public function setMode($mode){ + $this->mode = $mode; + } + + /** + * Get from time + * + * @return integer(unix_timestamp) from time + */ + public function getFromTime(){ + return $this->fromTime; + } + + /** + * Set from time + * + * @param integer $fromTime + * from time (unix_timestamp) + */ + public function setFromTime($fromTime){ + $this->fromTime = $fromTime; + } + +} diff --git a/Aliyun/Log/Models/GetHistogramsRequest.php b/Aliyun/Log/Models/Request/GetHistogramsRequest.php similarity index 95% rename from Aliyun/Log/Models/GetHistogramsRequest.php rename to Aliyun/Log/Models/Request/GetHistogramsRequest.php index 9fd2fc7..8df75e6 100644 --- a/Aliyun/Log/Models/GetHistogramsRequest.php +++ b/Aliyun/Log/Models/Request/GetHistogramsRequest.php @@ -1,161 +1,161 @@ -logstore = $logstore; - $this->from = $from; - $this->to = $to; - $this->topic = $topic; - $this->query = $query; - } - - /** - * Get logstore name - * - * @return string logstore name - */ - public function getLogstore() { - return $this->logstore; - } - - /** - * Set logstore name - * - * @param string $logstore - * logstore name - */ - public function setLogstore($logstore) { - $this->logstore = $logstore; - } - - /** - * Get topic name - * - * @return string topic name - */ - public function getTopic() { - return $this->topic; - } - - /** - * Set topic name - * - * @param string $topic - * topic name - */ - public function setTopic($topic) { - $this->topic = $topic; - } - - /** - * Get begin time - * - * @return integer begin time - */ - public function getFrom() { - return $this->from; - } - - /** - * Set begin time - * - * @param integer $from - * begin time - */ - public function setFrom($from) { - $this->from = $from; - } - - /** - * Get end time - * - * @return integer end time - */ - public function getTo() { - return $this->to; - } - - /** - * Set end time - * - * @param integer $to - * end time - */ - public function setTo($to) { - $this->to = $to; - } - - /** - * Get user defined query - * - * @return string user defined query - */ - public function getQuery() { - return $this->query; - } - - /** - * Set user defined query - * - * @param string $query - * user defined query - */ - public function setQuery($query) { - $this->query = $query; - } -} +logstore = $logstore; + $this->from = $from; + $this->to = $to; + $this->topic = $topic; + $this->query = $query; + } + + /** + * Get logstore name + * + * @return string logstore name + */ + public function getLogstore() { + return $this->logstore; + } + + /** + * Set logstore name + * + * @param string $logstore + * logstore name + */ + public function setLogstore($logstore) { + $this->logstore = $logstore; + } + + /** + * Get topic name + * + * @return string topic name + */ + public function getTopic() { + return $this->topic; + } + + /** + * Set topic name + * + * @param string $topic + * topic name + */ + public function setTopic($topic) { + $this->topic = $topic; + } + + /** + * Get begin time + * + * @return integer begin time + */ + public function getFrom() { + return $this->from; + } + + /** + * Set begin time + * + * @param integer $from + * begin time + */ + public function setFrom($from) { + $this->from = $from; + } + + /** + * Get end time + * + * @return integer end time + */ + public function getTo() { + return $this->to; + } + + /** + * Set end time + * + * @param integer $to + * end time + */ + public function setTo($to) { + $this->to = $to; + } + + /** + * Get user defined query + * + * @return string user defined query + */ + public function getQuery() { + return $this->query; + } + + /** + * Set user defined query + * + * @param string $query + * user defined query + */ + public function setQuery($query) { + $this->query = $query; + } +} diff --git a/Aliyun/Log/Models/GetLogsRequest.php b/Aliyun/Log/Models/Request/GetLogsRequest.php similarity index 95% rename from Aliyun/Log/Models/GetLogsRequest.php rename to Aliyun/Log/Models/Request/GetLogsRequest.php index c987259..32ef467 100644 --- a/Aliyun/Log/Models/GetLogsRequest.php +++ b/Aliyun/Log/Models/Request/GetLogsRequest.php @@ -1,242 +1,242 @@ -logstore = $logstore; - $this->from = $from; - $this->to = $to; - $this->topic = $topic; - $this->query = $query; - $this->line = $line; - $this->offset = $offset; - $this->reverse = $reverse; - } - - /** - * Get logstore name - * - * @return string logstore name - */ - public function getLogstore() { - return $this->logstore; - } - - /** - * Set logstore name - * - * @param string $logstore - * logstore name - */ - public function setLogstore($logstore) { - $this->logstore = $logstore; - } - - /** - * Get topic name - * - * @return string topic name - */ - public function getTopic() { - return $this->topic; - } - - /** - * Set topic name - * - * @param string $topic - * topic name - */ - public function setTopic($topic) { - $this->topic = $topic; - } - - /** - * Get begin time - * - * @return integer begin time - */ - public function getFrom() { - return $this->from; - } - - /** - * Set begin time - * - * @param integer $from - * begin time - */ - public function setFrom($from) { - $this->from = $from; - } - - /** - * Get end time - * - * @return integer end time - */ - public function getTo() { - return $this->to; - } - - /** - * Set end time - * - * @param integer $to - * end time - */ - public function setTo($to) { - $this->to = $to; - } - - /** - * Get user defined query - * - * @return string user defined query - */ - public function getQuery() { - return $this->query; - } - - /** - * Set user defined query - * - * @param string $query - * user defined query - */ - public function setQuery($query) { - $this->query = $query; - } - - /** - * Get max line number of return logs - * - * @return integer max line number of return logs - */ - public function getLine() { - return $this->line; - } - - /** - * Set max line number of return logs - * - * @param integer $line - * max line number of return logs - */ - public function setLine($line) { - $this->line = $line; - } - - /** - * Get line offset of return logs - * - * @return integer line offset of return logs - */ - public function getOffset() { - return $this->offset; - } - - /** - * Set request line offset of return logs - * - * @param integer $offset - * line offset of return logs - */ - public function setOffset($offset) { - $this->offset = $offset; - } - - /** - * Get request reverse flag - * - * @return bool reverse flag - */ - public function getReverse() { - return $this->reverse; - } - - /** - * Set request reverse flag - * - * @param bool $reverse - * reverse flag - */ - public function setReverse($reverse) { - $this->reverse = $reverse; - } -} +logstore = $logstore; + $this->from = $from; + $this->to = $to; + $this->topic = $topic; + $this->query = $query; + $this->line = $line; + $this->offset = $offset; + $this->reverse = $reverse; + } + + /** + * Get logstore name + * + * @return string logstore name + */ + public function getLogstore() { + return $this->logstore; + } + + /** + * Set logstore name + * + * @param string $logstore + * logstore name + */ + public function setLogstore($logstore) { + $this->logstore = $logstore; + } + + /** + * Get topic name + * + * @return string topic name + */ + public function getTopic() { + return $this->topic; + } + + /** + * Set topic name + * + * @param string $topic + * topic name + */ + public function setTopic($topic) { + $this->topic = $topic; + } + + /** + * Get begin time + * + * @return integer begin time + */ + public function getFrom() { + return $this->from; + } + + /** + * Set begin time + * + * @param integer $from + * begin time + */ + public function setFrom($from) { + $this->from = $from; + } + + /** + * Get end time + * + * @return integer end time + */ + public function getTo() { + return $this->to; + } + + /** + * Set end time + * + * @param integer $to + * end time + */ + public function setTo($to) { + $this->to = $to; + } + + /** + * Get user defined query + * + * @return string user defined query + */ + public function getQuery() { + return $this->query; + } + + /** + * Set user defined query + * + * @param string $query + * user defined query + */ + public function setQuery($query) { + $this->query = $query; + } + + /** + * Get max line number of return logs + * + * @return integer max line number of return logs + */ + public function getLine() { + return $this->line; + } + + /** + * Set max line number of return logs + * + * @param integer $line + * max line number of return logs + */ + public function setLine($line) { + $this->line = $line; + } + + /** + * Get line offset of return logs + * + * @return integer line offset of return logs + */ + public function getOffset() { + return $this->offset; + } + + /** + * Set request line offset of return logs + * + * @param integer $offset + * line offset of return logs + */ + public function setOffset($offset) { + $this->offset = $offset; + } + + /** + * Get request reverse flag + * + * @return bool reverse flag + */ + public function getReverse() { + return $this->reverse; + } + + /** + * Set request reverse flag + * + * @param bool $reverse + * reverse flag + */ + public function setReverse($reverse) { + $this->reverse = $reverse; + } +} diff --git a/Aliyun/Log/Models/GetMachineGroupRequest.php b/Aliyun/Log/Models/Request/GetMachineGroupRequest.php similarity index 95% rename from Aliyun/Log/Models/GetMachineGroupRequest.php rename to Aliyun/Log/Models/Request/GetMachineGroupRequest.php index 23aa3a8..8df5b03 100644 --- a/Aliyun/Log/Models/GetMachineGroupRequest.php +++ b/Aliyun/Log/Models/Request/GetMachineGroupRequest.php @@ -1,31 +1,31 @@ -groupName = $groupName; - } - public function getGroupName(){ - return $this->groupName; - } - public function setGroupName($groupName){ - $this->groupName = $groupName; - } - -} +groupName = $groupName; + } + public function getGroupName(){ + return $this->groupName; + } + public function setGroupName($groupName){ + $this->groupName = $groupName; + } + +} diff --git a/Aliyun/Log/Models/GetMachineRequest.php b/Aliyun/Log/Models/Request/GetMachineRequest.php similarity index 94% rename from Aliyun/Log/Models/GetMachineRequest.php rename to Aliyun/Log/Models/Request/GetMachineRequest.php index a21cb49..5100c22 100644 --- a/Aliyun/Log/Models/GetMachineRequest.php +++ b/Aliyun/Log/Models/Request/GetMachineRequest.php @@ -1,34 +1,34 @@ -uuid = $uuid; - } - - public function getUuid(){ - return $this->uuid; - } - - public function setUuid($uuid){ - $this->uuid = $uuid; - } - -} +uuid = $uuid; + } + + public function getUuid(){ + return $this->uuid; + } + + public function setUuid($uuid){ + $this->uuid = $uuid; + } + +} diff --git a/Aliyun/Log/Models/ListACLsRequest.php b/Aliyun/Log/Models/Request/ListACLsRequest.php similarity index 95% rename from Aliyun/Log/Models/ListACLsRequest.php rename to Aliyun/Log/Models/Request/ListACLsRequest.php index 801b512..d6311e1 100644 --- a/Aliyun/Log/Models/ListACLsRequest.php +++ b/Aliyun/Log/Models/Request/ListACLsRequest.php @@ -1,51 +1,51 @@ -offset = $offset; - $this->size = $size; - $this->principleId = $principleId; - } - - public function getOffset(){ - return $this->offset; - } - public function setOffset($offset){ - $this->offset = $offset; - } - - public function getSize(){ - return $this->size; - } - public function setSize($size){ - $this->size = $size; - } - - public function getPrincipleId(){ - return $this->principleId; - } - public function setPrincipleId($principleId){ - $this->principleId = $principleId; - } - -} +offset = $offset; + $this->size = $size; + $this->principleId = $principleId; + } + + public function getOffset(){ + return $this->offset; + } + public function setOffset($offset){ + $this->offset = $offset; + } + + public function getSize(){ + return $this->size; + } + public function setSize($size){ + $this->size = $size; + } + + public function getPrincipleId(){ + return $this->principleId; + } + public function setPrincipleId($principleId){ + $this->principleId = $principleId; + } + +} diff --git a/Aliyun/Log/Models/ListConfigsRequest.php b/Aliyun/Log/Models/Request/ListConfigsRequest.php similarity index 95% rename from Aliyun/Log/Models/ListConfigsRequest.php rename to Aliyun/Log/Models/Request/ListConfigsRequest.php index 76f5ef3..82049a2 100644 --- a/Aliyun/Log/Models/ListConfigsRequest.php +++ b/Aliyun/Log/Models/Request/ListConfigsRequest.php @@ -1,54 +1,54 @@ -configName = $configName; - $this->offset = $offset; - $this->size = $size; - } - - public function getConfigName(){ - return $this->configName; - } - - public function setConfigName($configName){ - $this->configName = $configName; - } - - public function getOffset(){ - return $this->offset; - } - - public function setOffset($offset){ - $this->offset = $offset; - } - - public function getSize(){ - return $this->size; - } - - public function setSize($size){ - $this->size = $size; - } -} +configName = $configName; + $this->offset = $offset; + $this->size = $size; + } + + public function getConfigName(){ + return $this->configName; + } + + public function setConfigName($configName){ + $this->configName = $configName; + } + + public function getOffset(){ + return $this->offset; + } + + public function setOffset($offset){ + $this->offset = $offset; + } + + public function getSize(){ + return $this->size; + } + + public function setSize($size){ + $this->size = $size; + } +} diff --git a/Aliyun/Log/Models/ListLogstoresRequest.php b/Aliyun/Log/Models/Request/ListLogstoresRequest.php similarity index 95% rename from Aliyun/Log/Models/ListLogstoresRequest.php rename to Aliyun/Log/Models/Request/ListLogstoresRequest.php index 215d35f..497afd7 100644 --- a/Aliyun/Log/Models/ListLogstoresRequest.php +++ b/Aliyun/Log/Models/Request/ListLogstoresRequest.php @@ -1,24 +1,24 @@ -groupName = $groupName; - $this->offset = $offset; - $this->size = $size; - } - - public function getGroupName(){ - return $this->groupName; - } - - public function setGroupName($groupName){ - $this->groupName = $groupName; - } - - public function getOffset(){ - return $this->offset; - } - - public function setOffset($offset){ - $this->offset = $offset; - } - - public function getSize(){ - return $this->size; - } - - public function setSize($size){ - $this->size = $size; - } -} +groupName = $groupName; + $this->offset = $offset; + $this->size = $size; + } + + public function getGroupName(){ + return $this->groupName; + } + + public function setGroupName($groupName){ + $this->groupName = $groupName; + } + + public function getOffset(){ + return $this->offset; + } + + public function setOffset($offset){ + $this->offset = $offset; + } + + public function getSize(){ + return $this->size; + } + + public function setSize($size){ + $this->size = $size; + } +} diff --git a/Aliyun/Log/Models/ListShardsRequest.php b/Aliyun/Log/Models/Request/ListShardsRequest.php similarity index 94% rename from Aliyun/Log/Models/ListShardsRequest.php rename to Aliyun/Log/Models/Request/ListShardsRequest.php index a837fd5..2bbf718 100644 --- a/Aliyun/Log/Models/ListShardsRequest.php +++ b/Aliyun/Log/Models/Request/ListShardsRequest.php @@ -1,36 +1,36 @@ -logstore = $logstore; - } - - public function getLogstore(){ - return $this->logstore; - } - - public function setLogstore($logstore){ - $this->logstore = $logstore; - } - - -} +logstore = $logstore; + } + + public function getLogstore(){ + return $this->logstore; + } + + public function setLogstore($logstore){ + $this->logstore = $logstore; + } + + +} diff --git a/Aliyun/Log/Models/ListTopicsRequest.php b/Aliyun/Log/Models/Request/ListTopicsRequest.php similarity index 95% rename from Aliyun/Log/Models/ListTopicsRequest.php rename to Aliyun/Log/Models/Request/ListTopicsRequest.php index 935ede7..60882c1 100644 --- a/Aliyun/Log/Models/ListTopicsRequest.php +++ b/Aliyun/Log/Models/Request/ListTopicsRequest.php @@ -1,102 +1,102 @@ -logstore = $logstore; - $this->token = $token; - $this->line = $line; - } - - /** - * Get logstroe name - * - * @return string logstore name - */ - public function getLogstore() { - return $this->logstore; - } - - /** - * Set logstore name - * - * @param string $logstore - * logstore name - */ - public function setLogstore($logstore) { - $this->logstore = $logstore; - } - - - /** - * Get start token to list topics - * - * @return string start token to list topics - */ - public function getToken() { - return $this->token; - } - - /** - * Set start token to list topics - * - * @param string $token start token to list topics - */ - public function setToken($token) { - $this->token = $token; - } - - - /** - * Get max topic counts to return - * - * @return integer max topic counts to return - */ - public function getLine() { - return $this->line; - } - - /** - * Set max topic counts to return - * - * @param integer $line max topic counts to return - */ - public function setLine($line) { - $this->line = $line; - } -} +logstore = $logstore; + $this->token = $token; + $this->line = $line; + } + + /** + * Get logstroe name + * + * @return string logstore name + */ + public function getLogstore() { + return $this->logstore; + } + + /** + * Set logstore name + * + * @param string $logstore + * logstore name + */ + public function setLogstore($logstore) { + $this->logstore = $logstore; + } + + + /** + * Get start token to list topics + * + * @return string start token to list topics + */ + public function getToken() { + return $this->token; + } + + /** + * Set start token to list topics + * + * @param string $token start token to list topics + */ + public function setToken($token) { + $this->token = $token; + } + + + /** + * Get max topic counts to return + * + * @return integer max topic counts to return + */ + public function getLine() { + return $this->line; + } + + /** + * Set max topic counts to return + * + * @param integer $line max topic counts to return + */ + public function setLine($line) { + $this->line = $line; + } +} diff --git a/Aliyun/Log/Models/MergeShardsRequest.php b/Aliyun/Log/Models/Request/MergeShardsRequest.php similarity index 95% rename from Aliyun/Log/Models/MergeShardsRequest.php rename to Aliyun/Log/Models/Request/MergeShardsRequest.php index 4924173..31512a6 100644 --- a/Aliyun/Log/Models/MergeShardsRequest.php +++ b/Aliyun/Log/Models/Request/MergeShardsRequest.php @@ -1,39 +1,39 @@ -logstore = $logstore; - $this->shardId = $shardId; - } - - public function getLogstore(){ - return $this->logstore; - } - - public function setLogstore($logstore){ - $this->logstore = $logstore; - } - - public function getShardId(){ - return $this->shardId; - } -} +logstore = $logstore; + $this->shardId = $shardId; + } + + public function getLogstore(){ + return $this->logstore; + } + + public function setLogstore($logstore){ + $this->logstore = $logstore; + } + + public function getShardId(){ + return $this->shardId; + } +} diff --git a/Aliyun/Log/Models/PutLogsRequest.php b/Aliyun/Log/Models/Request/PutLogsRequest.php similarity index 95% rename from Aliyun/Log/Models/PutLogsRequest.php rename to Aliyun/Log/Models/Request/PutLogsRequest.php index 7d3a1a2..f72ab4e 100644 --- a/Aliyun/Log/Models/PutLogsRequest.php +++ b/Aliyun/Log/Models/Request/PutLogsRequest.php @@ -1,156 +1,156 @@ -logstore = $logstore; - $this->topic = $topic; - $this->source = $source; - $this->logitems = $logitems; - $this->shardKey = $shardKey; - } - - /** - * Get logstroe name - * - * @return string logstore name - */ - public function getLogstore() { - return $this->logstore; - } - - /** - * Set logstore name - * - * @param string $logstore - * logstore name - */ - public function setLogstore($logstore) { - $this->logstore = $logstore; - } - - /** - * Get topic name - * - * @return string topic name - */ - public function getTopic() { - return $this->topic; - } - - /** - * Set topic name - * - * @param string $topic - * topic name - */ - public function setTopic($topic) { - $this->topic = $topic; - } - - /** - * Get all the log data - * - * @return array LogItem array, log data - */ - public function getLogItems() { - return $this->logitems; - } - - /** - * Set the log data - * - * @param array $logitems - * LogItem array, log data - */ - public function setLogItems($logitems) { - $this->logitems = $logitems; - } - - /** - * Get log source - * - * @return string log source - */ - public function getSource() { - return $this->source; - } - - /** - * set log source - * - * @param string $source - * log source - */ - public function setSource($source) { - $this->source = $source; - } - /** - * set shard key - * - * @param string shardkey - */ - public function setShardKey($key){ - $this -> shardKey=$key; - } - /** - * get shard key - * - * @return string shardKey - */ - public function getShardKey(){ - return $this ->shardKey; - } -} +logstore = $logstore; + $this->topic = $topic; + $this->source = $source; + $this->logitems = $logitems; + $this->shardKey = $shardKey; + } + + /** + * Get logstroe name + * + * @return string logstore name + */ + public function getLogstore() { + return $this->logstore; + } + + /** + * Set logstore name + * + * @param string $logstore + * logstore name + */ + public function setLogstore($logstore) { + $this->logstore = $logstore; + } + + /** + * Get topic name + * + * @return string topic name + */ + public function getTopic() { + return $this->topic; + } + + /** + * Set topic name + * + * @param string $topic + * topic name + */ + public function setTopic($topic) { + $this->topic = $topic; + } + + /** + * Get all the log data + * + * @return array LogItem array, log data + */ + public function getLogItems() { + return $this->logitems; + } + + /** + * Set the log data + * + * @param array $logitems + * LogItem array, log data + */ + public function setLogItems($logitems) { + $this->logitems = $logitems; + } + + /** + * Get log source + * + * @return string log source + */ + public function getSource() { + return $this->source; + } + + /** + * set log source + * + * @param string $source + * log source + */ + public function setSource($source) { + $this->source = $source; + } + /** + * set shard key + * + * @param string shardkey + */ + public function setShardKey($key){ + $this -> shardKey=$key; + } + /** + * get shard key + * + * @return string shardKey + */ + public function getShardKey(){ + return $this ->shardKey; + } +} diff --git a/Aliyun/Log/Models/RemoveConfigFromMachineGroupRequest.php b/Aliyun/Log/Models/Request/RemoveConfigFromMachineGroupRequest.php similarity index 95% rename from Aliyun/Log/Models/RemoveConfigFromMachineGroupRequest.php rename to Aliyun/Log/Models/Request/RemoveConfigFromMachineGroupRequest.php index cdd8ce9..193c2f8 100644 --- a/Aliyun/Log/Models/RemoveConfigFromMachineGroupRequest.php +++ b/Aliyun/Log/Models/Request/RemoveConfigFromMachineGroupRequest.php @@ -1,40 +1,40 @@ -groupName = $groupName; - $this->configName = $configName; - } - public function getGroupName(){ - return $this->groupName; - } - public function setGroupName($groupName){ - $this->groupName = $groupName; - } - - public function getConfigName(){ - return $this->configName; - } - public function setConfigName($configName){ - $this->configName = $configName; - } - -} +groupName = $groupName; + $this->configName = $configName; + } + public function getGroupName(){ + return $this->groupName; + } + public function setGroupName($groupName){ + $this->groupName = $groupName; + } + + public function getConfigName(){ + return $this->configName; + } + public function setConfigName($configName){ + $this->configName = $configName; + } + +} diff --git a/Aliyun/Log/Models/Request.php b/Aliyun/Log/Models/Request/Request.php similarity index 94% rename from Aliyun/Log/Models/Request.php rename to Aliyun/Log/Models/Request/Request.php index 05df3f0..43efbc2 100644 --- a/Aliyun/Log/Models/Request.php +++ b/Aliyun/Log/Models/Request/Request.php @@ -1,47 +1,47 @@ -project = $project; - } - - /** - * Get project name - * - * @return string project name - */ - public function getProject() { - return $this->project; - } - - /** - * Set project name - * - * @param string $project - * project name - */ - public function setProject($project) { - $this->project = $project; - } -} +project = $project; + } + + /** + * Get project name + * + * @return string project name + */ + public function getProject() { + return $this->project; + } + + /** + * Set project name + * + * @param string $project + * project name + */ + public function setProject($project) { + $this->project = $project; + } +} diff --git a/Aliyun/Log/Models/SplitShardRequest.php b/Aliyun/Log/Models/Request/SplitShardRequest.php similarity index 95% rename from Aliyun/Log/Models/SplitShardRequest.php rename to Aliyun/Log/Models/Request/SplitShardRequest.php index b628433..129b87e 100644 --- a/Aliyun/Log/Models/SplitShardRequest.php +++ b/Aliyun/Log/Models/Request/SplitShardRequest.php @@ -1,44 +1,44 @@ -logstore = $logstore; - $this->shardId = $shardId; - $this->midHash = $midHash; - } - - public function getLogstore(){ - return $this->logstore; - } - - public function setLogstore($logstore){ - $this->logstore = $logstore; - } - - public function getShardId(){ - return $this->shardId; - } - public function getMidHash(){ - return $this->midHash; - } - -} +logstore = $logstore; + $this->shardId = $shardId; + $this->midHash = $midHash; + } + + public function getLogstore(){ + return $this->logstore; + } + + public function setLogstore($logstore){ + $this->logstore = $logstore; + } + + public function getShardId(){ + return $this->shardId; + } + public function getMidHash(){ + return $this->midHash; + } + +} diff --git a/Aliyun/Log/Models/UpdateACLRequest.php b/Aliyun/Log/Models/Request/UpdateACLRequest.php similarity index 94% rename from Aliyun/Log/Models/UpdateACLRequest.php rename to Aliyun/Log/Models/Request/UpdateACLRequest.php index a8f21b8..f9cc97d 100644 --- a/Aliyun/Log/Models/UpdateACLRequest.php +++ b/Aliyun/Log/Models/Request/UpdateACLRequest.php @@ -1,31 +1,31 @@ -acl = $acl; - } - - public function getAcl(){ - return $this->acl; - } - public function setAcl($acl){ - $this->acl = $acl; - } -} +acl = $acl; + } + + public function getAcl(){ + return $this->acl; + } + public function setAcl($acl){ + $this->acl = $acl; + } +} diff --git a/Aliyun/Log/Models/UpdateConfigRequest.php b/Aliyun/Log/Models/Request/UpdateConfigRequest.php similarity index 94% rename from Aliyun/Log/Models/UpdateConfigRequest.php rename to Aliyun/Log/Models/Request/UpdateConfigRequest.php index 327040a..6549594 100644 --- a/Aliyun/Log/Models/UpdateConfigRequest.php +++ b/Aliyun/Log/Models/Request/UpdateConfigRequest.php @@ -1,33 +1,33 @@ -config = $config; - } - - public function getConfig(){ - return $this->config; - } - - public function setConfig($config){ - $this->config = $config; - } - -} +config = $config; + } + + public function getConfig(){ + return $this->config; + } + + public function setConfig($config){ + $this->config = $config; + } + +} diff --git a/Aliyun/Log/Models/UpdateLogstoreRequest.php b/Aliyun/Log/Models/Request/UpdateLogstoreRequest.php similarity index 95% rename from Aliyun/Log/Models/UpdateLogstoreRequest.php rename to Aliyun/Log/Models/Request/UpdateLogstoreRequest.php index be1a19b..874a70a 100644 --- a/Aliyun/Log/Models/UpdateLogstoreRequest.php +++ b/Aliyun/Log/Models/Request/UpdateLogstoreRequest.php @@ -1,42 +1,42 @@ - logstore = $logstore; - $this -> ttl = $ttl; - $this -> shardCount = $shardCount; - } - public function getLogstore() - { - return $this -> logstore; - } - public function getTtl() - { - return $this -> ttl; - } - public function getShardCount() - { - return $this -> shardCount; - } -} + logstore = $logstore; + $this -> ttl = $ttl; + $this -> shardCount = $shardCount; + } + public function getLogstore() + { + return $this -> logstore; + } + public function getTtl() + { + return $this -> ttl; + } + public function getShardCount() + { + return $this -> shardCount; + } +} diff --git a/Aliyun/Log/Models/UpdateMachineGroupRequest.php b/Aliyun/Log/Models/Request/UpdateMachineGroupRequest.php similarity index 95% rename from Aliyun/Log/Models/UpdateMachineGroupRequest.php rename to Aliyun/Log/Models/Request/UpdateMachineGroupRequest.php index 4de8518..719ef6e 100644 --- a/Aliyun/Log/Models/UpdateMachineGroupRequest.php +++ b/Aliyun/Log/Models/Request/UpdateMachineGroupRequest.php @@ -1,34 +1,34 @@ -machineGroup = $machineGroup; - } - - public function getMachineGroup(){ - return $this->machineGroup; - } - - public function setMachineGroup($machineGroup){ - $this->machineGroup = $machineGroup; - } - - -} +machineGroup = $machineGroup; + } + + public function getMachineGroup(){ + return $this->machineGroup; + } + + public function setMachineGroup($machineGroup){ + $this->machineGroup = $machineGroup; + } + + +} diff --git a/Aliyun/Log/Models/ApplyConfigToMachineGroupResponse.php b/Aliyun/Log/Models/Response/ApplyConfigToMachineGroupResponse.php similarity index 95% rename from Aliyun/Log/Models/ApplyConfigToMachineGroupResponse.php rename to Aliyun/Log/Models/Response/ApplyConfigToMachineGroupResponse.php index 29777b6..253e1ac 100644 --- a/Aliyun/Log/Models/ApplyConfigToMachineGroupResponse.php +++ b/Aliyun/Log/Models/Response/ApplyConfigToMachineGroupResponse.php @@ -1,29 +1,29 @@ -logPackageList = $resp->getLogGroupListArray(); - $this->nextCursor = (isset($header['x-log-cursor']))?$header['x-log-cursor']:null; - - } - - public function getLogPackageList(){ - return $this->logPackageList; - } - - public function getNextCursor(){ - return $this->nextCursor; - } - - public function getCount() { - return count($this->logPackageList); - } - - public function getLogPackage($index){ - if($index<$this->getCount()){ - return $this->logPackageList[$index]; - } - else{ - throw new OutOfBoundsException('Index must less than size of logPackageList'); - } - } - - public function getLogGroupList(){ - return $this->logPackageList; - } - - public function getLogGroup($index){ - if($index<$this->getCount()){ - return $this->logPackageList[$index]; - } - else{ - throw new OutOfBoundsException('Index must less than size of logPackageList'); - } - } - - -} +logPackageList = $resp->getLogGroupListArray(); + $this->nextCursor = (isset($header['x-log-cursor']))?$header['x-log-cursor']:null; + + } + + public function getLogPackageList(){ + return $this->logPackageList; + } + + public function getNextCursor(){ + return $this->nextCursor; + } + + public function getCount() { + return count($this->logPackageList); + } + + public function getLogPackage($index){ + if($index<$this->getCount()){ + return $this->logPackageList[$index]; + } + else{ + throw new OutOfBoundsException('Index must less than size of logPackageList'); + } + } + + public function getLogGroupList(){ + return $this->logPackageList; + } + + public function getLogGroup($index){ + if($index<$this->getCount()){ + return $this->logPackageList[$index]; + } + else{ + throw new OutOfBoundsException('Index must less than size of logPackageList'); + } + } + + +} diff --git a/Aliyun/Log/Models/CreateACLResponse.php b/Aliyun/Log/Models/Response/CreateACLResponse.php similarity index 95% rename from Aliyun/Log/Models/CreateACLResponse.php rename to Aliyun/Log/Models/Response/CreateACLResponse.php index 3637cea..c075b60 100644 --- a/Aliyun/Log/Models/CreateACLResponse.php +++ b/Aliyun/Log/Models/Response/CreateACLResponse.php @@ -1,33 +1,33 @@ -aclId = $resp['aclId']; - } - public function getAclId(){ - return $this->aclId; - } - -} +aclId = $resp['aclId']; + } + public function getAclId(){ + return $this->aclId; + } + +} diff --git a/Aliyun/Log/Models/CreateConfigResponse.php b/Aliyun/Log/Models/Response/CreateConfigResponse.php similarity index 95% rename from Aliyun/Log/Models/CreateConfigResponse.php rename to Aliyun/Log/Models/Response/CreateConfigResponse.php index 4f53f63..99e2263 100644 --- a/Aliyun/Log/Models/CreateConfigResponse.php +++ b/Aliyun/Log/Models/Response/CreateConfigResponse.php @@ -1,29 +1,29 @@ -acl = null; - if($resp!==null){ - $this->acl = new Aliyun_Log_Models_ACL(); - $this->acl->setFromArray($resp); - } - } - - public function getAcl(){ - return $this->acl; - } - - -} +acl = null; + if($resp!==null){ + $this->acl = new Aliyun_Log_Models_ACL(); + $this->acl->setFromArray($resp); + } + } + + public function getAcl(){ + return $this->acl; + } + + +} diff --git a/Aliyun/Log/Models/GetConfigResponse.php b/Aliyun/Log/Models/Response/GetConfigResponse.php similarity index 95% rename from Aliyun/Log/Models/GetConfigResponse.php rename to Aliyun/Log/Models/Response/GetConfigResponse.php index 7c5c8bb..a4619a2 100644 --- a/Aliyun/Log/Models/GetConfigResponse.php +++ b/Aliyun/Log/Models/Response/GetConfigResponse.php @@ -1,37 +1,37 @@ -config = new Aliyun_Log_Models_Config(); - $this->config->setFromArray($resp); - } - - public function getConfig(){ - return $this->config; - } - -} +config = new Aliyun_Log_Models_Config(); + $this->config->setFromArray($resp); + } + + public function getConfig(){ + return $this->config; + } + +} diff --git a/Aliyun/Log/Models/GetCursorResponse.php b/Aliyun/Log/Models/Response/GetCursorResponse.php similarity index 95% rename from Aliyun/Log/Models/GetCursorResponse.php rename to Aliyun/Log/Models/Response/GetCursorResponse.php index d09f6d9..320c0e9 100644 --- a/Aliyun/Log/Models/GetCursorResponse.php +++ b/Aliyun/Log/Models/Response/GetCursorResponse.php @@ -1,41 +1,41 @@ -cursor = $resp['cursor']; - } - - /** - * Get cursor from the response - * - * @return string cursor - */ - public function getCursor(){ - return $this->cursor; - } -} +cursor = $resp['cursor']; + } + + /** + * Get cursor from the response + * + * @return string cursor + */ + public function getCursor(){ + return $this->cursor; + } +} diff --git a/Aliyun/Log/Models/GetHistogramsResponse.php b/Aliyun/Log/Models/Response/GetHistogramsResponse.php similarity index 96% rename from Aliyun/Log/Models/GetHistogramsResponse.php rename to Aliyun/Log/Models/Response/GetHistogramsResponse.php index d7acd59..b5514f5 100644 --- a/Aliyun/Log/Models/GetHistogramsResponse.php +++ b/Aliyun/Log/Models/Response/GetHistogramsResponse.php @@ -1,77 +1,77 @@ - - - /** - * Aliyun_Log_Models_GetHistogramsResponse constructor - * - * @param array $resp - * GetHistogramsResponse HTTP response body - * @param array $header - * GetHistogramsResponse HTTP response header - */ - public function __construct($resp, $header) { - parent::__construct ( $header ); - $this->progress = $header ['x-log-progress']; - $this->count = $header ['x-log-count']; - $this->histograms = array (); - foreach ( $resp as $data ) - $this->histograms [] = new Aliyun_Log_Models_Histogram ( $data ['from'], $data ['to'], $data ['count'], $data ['progress'] ); - } - - /** - * Check if the histogram is completed - * - * @return bool true if this histogram is completed - */ - public function isCompleted() { - return $this->progress == 'Complete'; - } - - /** - * Get total logs' count that current query hits - * - * @return integer total logs' count that current query hits - */ - public function getTotalCount() { - return $this->count; - } - - /** - * Get histograms on the requested time range: [from, to) - * - * @return array Aliyun_Log_Models_Histogram array, histograms on the requested time range - */ - public function getHistograms() { - return $this->histograms; - } -} + + + /** + * Aliyun_Log_Models_GetHistogramsResponse constructor + * + * @param array $resp + * GetHistogramsResponse HTTP response body + * @param array $header + * GetHistogramsResponse HTTP response header + */ + public function __construct($resp, $header) { + parent::__construct ( $header ); + $this->progress = $header ['x-log-progress']; + $this->count = $header ['x-log-count']; + $this->histograms = array (); + foreach ( $resp as $data ) + $this->histograms [] = new Aliyun_Log_Models_Histogram ( $data ['from'], $data ['to'], $data ['count'], $data ['progress'] ); + } + + /** + * Check if the histogram is completed + * + * @return bool true if this histogram is completed + */ + public function isCompleted() { + return $this->progress == 'Complete'; + } + + /** + * Get total logs' count that current query hits + * + * @return integer total logs' count that current query hits + */ + public function getTotalCount() { + return $this->count; + } + + /** + * Get histograms on the requested time range: [from, to) + * + * @return array Aliyun_Log_Models_Histogram array, histograms on the requested time range + */ + public function getHistograms() { + return $this->histograms; + } +} diff --git a/Aliyun/Log/Models/GetLogsResponse.php b/Aliyun/Log/Models/Response/GetLogsResponse.php similarity index 96% rename from Aliyun/Log/Models/GetLogsResponse.php rename to Aliyun/Log/Models/Response/GetLogsResponse.php index 4531931..d56dc0c 100644 --- a/Aliyun/Log/Models/GetLogsResponse.php +++ b/Aliyun/Log/Models/Response/GetLogsResponse.php @@ -1,81 +1,81 @@ -count = $header['x-log-count']; - $this->progress = $header ['x-log-progress']; - $this->logs = array (); - foreach ( $resp as $data ) { - $contents = $data; - $time = $data ['__time__']; - $source = $data ['__source__']; - unset ( $contents ['__time__'] ); - unset ( $contents ['__source__'] ); - $this->logs [] = new Aliyun_Log_Models_QueriedLog ( $time, $source, $contents ); - } - } - - /** - * Get log number from the response - * - * @return integer log number - */ - public function getCount() { - return $this->count; - } - - /** - * Check if the get logs query is completed - * - * @return bool true if this logs query is completed - */ - public function isCompleted() { - return $this->progress == 'Complete'; - } - - /** - * Get all logs from the response - * - * @return array Aliyun_Log_Models_QueriedLog array, all log data - */ - public function getLogs() { - return $this->logs; - } -} +count = $header['x-log-count']; + $this->progress = $header ['x-log-progress']; + $this->logs = array (); + foreach ( $resp as $data ) { + $contents = $data; + $time = $data ['__time__']; + $source = $data ['__source__']; + unset ( $contents ['__time__'] ); + unset ( $contents ['__source__'] ); + $this->logs [] = new Aliyun_Log_Models_QueriedLog ( $time, $source, $contents ); + } + } + + /** + * Get log number from the response + * + * @return integer log number + */ + public function getCount() { + return $this->count; + } + + /** + * Check if the get logs query is completed + * + * @return bool true if this logs query is completed + */ + public function isCompleted() { + return $this->progress == 'Complete'; + } + + /** + * Get all logs from the response + * + * @return array Aliyun_Log_Models_QueriedLog array, all log data + */ + public function getLogs() { + return $this->logs; + } +} diff --git a/Aliyun/Log/Models/GetMachineGroupResponse.php b/Aliyun/Log/Models/Response/GetMachineGroupResponse.php similarity index 96% rename from Aliyun/Log/Models/GetMachineGroupResponse.php rename to Aliyun/Log/Models/Response/GetMachineGroupResponse.php index 2d47636..3bb8b3c 100644 --- a/Aliyun/Log/Models/GetMachineGroupResponse.php +++ b/Aliyun/Log/Models/Response/GetMachineGroupResponse.php @@ -1,36 +1,36 @@ -machineGroup = new Aliyun_Log_Models_MachineGroup(); - $this->machineGroup->setFromArray($resp); - } - - public function getMachineGroup(){ - return $this->machineGroup; - } - -} +machineGroup = new Aliyun_Log_Models_MachineGroup(); + $this->machineGroup->setFromArray($resp); + } + + public function getMachineGroup(){ + return $this->machineGroup; + } + +} diff --git a/Aliyun/Log/Models/GetMachineResponse.php b/Aliyun/Log/Models/Response/GetMachineResponse.php similarity index 95% rename from Aliyun/Log/Models/GetMachineResponse.php rename to Aliyun/Log/Models/Response/GetMachineResponse.php index 670d2f9..fe98f7f 100644 --- a/Aliyun/Log/Models/GetMachineResponse.php +++ b/Aliyun/Log/Models/Response/GetMachineResponse.php @@ -1,38 +1,38 @@ -machine = new Aliyun_Log_Models_Machine(); - $this->machine->setFromArray($resp); - - } - - public function getMachine(){ - return $this->machine; - } - -} +machine = new Aliyun_Log_Models_Machine(); + $this->machine->setFromArray($resp); + + } + + public function getMachine(){ + return $this->machine; + } + +} diff --git a/Aliyun/Log/Models/ListACLsResponse.php b/Aliyun/Log/Models/Response/ListACLsResponse.php similarity index 95% rename from Aliyun/Log/Models/ListACLsResponse.php rename to Aliyun/Log/Models/Response/ListACLsResponse.php index ce479ef..ca3bf20 100644 --- a/Aliyun/Log/Models/ListACLsResponse.php +++ b/Aliyun/Log/Models/Response/ListACLsResponse.php @@ -1,44 +1,44 @@ -setFromArray($value); - $aclArr[]=$aclObj; - } - } - $this->acls = $aclArr; - } - - public function getAcls(){ - return $this->acls; - } - - -} +setFromArray($value); + $aclArr[]=$aclObj; + } + } + $this->acls = $aclArr; + } + + public function getAcls(){ + return $this->acls; + } + + +} diff --git a/Aliyun/Log/Models/ListConfigsResponse.php b/Aliyun/Log/Models/Response/ListConfigsResponse.php similarity index 95% rename from Aliyun/Log/Models/ListConfigsResponse.php rename to Aliyun/Log/Models/Response/ListConfigsResponse.php index 0a5d231..fcaf0a7 100644 --- a/Aliyun/Log/Models/ListConfigsResponse.php +++ b/Aliyun/Log/Models/Response/ListConfigsResponse.php @@ -1,44 +1,44 @@ -size = $resp['total']; - $this->configs = $resp['configs']; - } - - public function getSize(){ - return count($this->configs); - } - - public function getTotal(){ - return $this ->total; - } - - public function getConfigs(){ - return $this->configs; - } - - -} +size = $resp['total']; + $this->configs = $resp['configs']; + } + + public function getSize(){ + return count($this->configs); + } + + public function getTotal(){ + return $this ->total; + } + + public function getConfigs(){ + return $this->configs; + } + + +} diff --git a/Aliyun/Log/Models/ListLogstoresResponse.php b/Aliyun/Log/Models/Response/ListLogstoresResponse.php similarity index 95% rename from Aliyun/Log/Models/ListLogstoresResponse.php rename to Aliyun/Log/Models/Response/ListLogstoresResponse.php index a6ba1f2..b62c72a 100644 --- a/Aliyun/Log/Models/ListLogstoresResponse.php +++ b/Aliyun/Log/Models/Response/ListLogstoresResponse.php @@ -1,57 +1,57 @@ -count = $resp ['total']; - $this->logstores = $resp ['logstores']; - } - - /** - * Get total count of logstores from the response - * - * @return integer the number of total logstores from the response - */ - public function getCount() { - return $this->count; - } - - /** - * Get all the logstores from the response - * - * @return array all logstore - */ - public function getLogstores() { - return $this->logstores; - } -} +count = $resp ['total']; + $this->logstores = $resp ['logstores']; + } + + /** + * Get total count of logstores from the response + * + * @return integer the number of total logstores from the response + */ + public function getCount() { + return $this->count; + } + + /** + * Get all the logstores from the response + * + * @return array all logstore + */ + public function getLogstores() { + return $this->logstores; + } +} diff --git a/Aliyun/Log/Models/ListMachineGroupsResponse.php b/Aliyun/Log/Models/Response/ListMachineGroupsResponse.php similarity index 95% rename from Aliyun/Log/Models/ListMachineGroupsResponse.php rename to Aliyun/Log/Models/Response/ListMachineGroupsResponse.php index 9ef203f..84b3443 100644 --- a/Aliyun/Log/Models/ListMachineGroupsResponse.php +++ b/Aliyun/Log/Models/Response/ListMachineGroupsResponse.php @@ -1,45 +1,45 @@ -offset = $resp['offset']; - $this->size = $resp['size']; - $this->machineGroups = $resp['machinegroups']; - } - - public function getOffset(){ - return $this->offset; - } - - public function getSize(){ - return $this->size; - } - - public function getMachineGroups(){ - return $this->machineGroups; - } -} +offset = $resp['offset']; + $this->size = $resp['size']; + $this->machineGroups = $resp['machinegroups']; + } + + public function getOffset(){ + return $this->offset; + } + + public function getSize(){ + return $this->size; + } + + public function getMachineGroups(){ + return $this->machineGroups; + } +} diff --git a/Aliyun/Log/Models/ListShardsResponse.php b/Aliyun/Log/Models/Response/ListShardsResponse.php similarity index 93% rename from Aliyun/Log/Models/ListShardsResponse.php rename to Aliyun/Log/Models/Response/ListShardsResponse.php index 90da484..8722328 100644 --- a/Aliyun/Log/Models/ListShardsResponse.php +++ b/Aliyun/Log/Models/Response/ListShardsResponse.php @@ -1,43 +1,43 @@ -$value){ - var_dump($value); - $this->shardIds[] = $value['shardID']; - $this->shards[] = new Aliyun_Log_Models_Shard($value['shardID'],$value["status"],$value["inclusiveBeginKey"],$value["exclusiveEndKey"],$value["createTime"]); - } - } - - public function getShardIds(){ - return $this->shardIds; - } - public function getShards() - { - return $this -> shards; - } - -} +$value){ + var_dump($value); + $this->shardIds[] = $value['shardID']; + $this->shards[] = new Aliyun_Log_Models_Shard($value['shardID'],$value["status"],$value["inclusiveBeginKey"],$value["exclusiveEndKey"],$value["createTime"]); + } + } + + public function getShardIds(){ + return $this-> shardIds; + } + public function getShards() + { + return $this -> shards; + } + +} diff --git a/Aliyun/Log/Models/ListTopicsResponse.php b/Aliyun/Log/Models/Response/ListTopicsResponse.php similarity index 96% rename from Aliyun/Log/Models/ListTopicsResponse.php rename to Aliyun/Log/Models/Response/ListTopicsResponse.php index d28132a..a41a9ed 100644 --- a/Aliyun/Log/Models/ListTopicsResponse.php +++ b/Aliyun/Log/Models/Response/ListTopicsResponse.php @@ -1,73 +1,73 @@ -count = $header['x-log-count']; - $this->topics = $resp ; - $this->nextToken = isset ( $header['x-log-nexttoken'] ) ? $header['x-log-nexttoken'] : NULL; - } - - /** - * Get the number of all the topics from the response - * - * @return integer the number of all the topics from the response - */ - public function getCount() { - return $this->count; - } - - /** - * Get all the topics from the response - * - * @return array topics list - */ - public function getTopics() { - return $this->topics; - } - - /** - * Return the next token from the response. If there is no more topic to list, it will return None - * - * @return string/null next token used to list more topics - */ - public function getNextToken() { - return $this->nextToken; - } -} +count = $header['x-log-count']; + $this->topics = $resp ; + $this->nextToken = isset ( $header['x-log-nexttoken'] ) ? $header['x-log-nexttoken'] : NULL; + } + + /** + * Get the number of all the topics from the response + * + * @return integer the number of all the topics from the response + */ + public function getCount() { + return $this->count; + } + + /** + * Get all the topics from the response + * + * @return array topics list + */ + public function getTopics() { + return $this->topics; + } + + /** + * Return the next token from the response. If there is no more topic to list, it will return None + * + * @return string/null next token used to list more topics + */ + public function getNextToken() { + return $this->nextToken; + } +} diff --git a/Aliyun/Log/Models/PutLogsResponse.php b/Aliyun/Log/Models/Response/PutLogsResponse.php similarity index 95% rename from Aliyun/Log/Models/PutLogsResponse.php rename to Aliyun/Log/Models/Response/PutLogsResponse.php index f17a797..c68191f 100644 --- a/Aliyun/Log/Models/PutLogsResponse.php +++ b/Aliyun/Log/Models/Response/PutLogsResponse.php @@ -1,24 +1,24 @@ -headers = $headers; - } - - /** - * Get all http headers - * - * @return array HTTP response header - */ - public function getAllHeaders() { - return $this->headers; - } - - /** - * Get specified http header - * - * @param string $key - * key to get header - * - * @return string HTTP response header. '' will be return if not set. - */ - public function getHeader($key) { - return isset ($this->headers[$key]) ? $this->headers [$key] : ''; - } - - /** - * Get the request id of the response. '' will be return if not set. - * - * @return string request id - */ - public function getRequestId() { - return isset ( $this->headers ['x-log-requestid'] ) ? $this->headers ['x-log-requestid'] : ''; - } -} +headers = $headers; + } + + /** + * Get all http headers + * + * @return array HTTP response header + */ + public function getAllHeaders() { + return $this->headers; + } + + /** + * Get specified http header + * + * @param string $key + * key to get header + * + * @return string HTTP response header. '' will be return if not set. + */ + public function getHeader($key) { + return isset ($this->headers[$key]) ? $this->headers [$key] : ''; + } + + /** + * Get the request id of the response. '' will be return if not set. + * + * @return string request id + */ + public function getRequestId() { + return isset ( $this->headers ['x-log-requestid'] ) ? $this->headers ['x-log-requestid'] : ''; + } +} diff --git a/Aliyun/Log/Models/Shard.php b/Aliyun/Log/Models/Response/Shard.php similarity index 100% rename from Aliyun/Log/Models/Shard.php rename to Aliyun/Log/Models/Response/Shard.php diff --git a/Aliyun/Log/Models/UpdateACLResponse.php b/Aliyun/Log/Models/Response/UpdateACLResponse.php similarity index 95% rename from Aliyun/Log/Models/UpdateACLResponse.php rename to Aliyun/Log/Models/Response/UpdateACLResponse.php index 7aace52..4c58a82 100644 --- a/Aliyun/Log/Models/UpdateACLResponse.php +++ b/Aliyun/Log/Models/Response/UpdateACLResponse.php @@ -1,29 +1,29 @@ -getConstants(); + } + return self::$constCacheArray[$calledClass]; + } + + public static function isValidName($name, $strict = false){ + $constans = self::getConstants(); + + if($strict){ + return array_key_exists($name, $constans); + } + + $keys = array_map('strtolower', array_keys($constans)); + return in_array(strtolower($name), $keys); + } + + public static function isValidValue($value, $strict = true){ + $values = array_values(self::getConstants()); + return in_array($value, $values, $strict); + } +} \ No newline at end of file diff --git a/Aliyun/Log/protocolbuffers.inc.php b/Aliyun/Log/protocolbuffers.inc.php index ec4f326..9e363d7 100644 --- a/Aliyun/Log/protocolbuffers.inc.php +++ b/Aliyun/Log/protocolbuffers.inc.php @@ -147,14 +147,14 @@ public static function read_varint($fp, &$limit = null) { return $i; } - public static function read_double($fp){throw "I've not coded it yet Exception";} - public static function read_float ($fp){throw "I've not coded it yet Exception";} - public static function read_uint64($fp){throw "I've not coded it yet Exception";} - public static function read_int64 ($fp){throw "I've not coded it yet Exception";} - public static function read_uint32($fp){throw "I've not coded it yet Exception";} - public static function read_int32 ($fp){throw "I've not coded it yet Exception";} - public static function read_zint32($fp){throw "I've not coded it yet Exception";} - public static function read_zint64($fp){throw "I've not coded it yet Exception";} + public static function read_double($fp){throw new Exception("I've not coded it yet Exception");} + public static function read_float ($fp){throw new Exception("I've not coded it yet Exception");} + public static function read_uint64($fp){throw new Exception("I've not coded it yet Exception");} + public static function read_int64 ($fp){throw new Exception("I've not coded it yet Exception");} + public static function read_uint32($fp){throw new Exception("I've not coded it yet Exception");} + public static function read_int32 ($fp){throw new Exception("I've not coded it yet Exception");} + public static function read_zint32($fp){throw new Exception("I've not coded it yet Exception");} + public static function read_zint64($fp){throw new Exception("I've not coded it yet Exception");} /** * Writes a varint to $fp @@ -181,14 +181,14 @@ public static function write_varint($fp, $i) { return $len; } - public static function write_double($fp, $d){throw "I've not coded it yet Exception";} - public static function write_float ($fp, $f){throw "I've not coded it yet Exception";} - public static function write_uint64($fp, $i){throw "I've not coded it yet Exception";} - public static function write_int64 ($fp, $i){throw "I've not coded it yet Exception";} - public static function write_uint32($fp, $i){throw "I've not coded it yet Exception";} - public static function write_int32 ($fp, $i){throw "I've not coded it yet Exception";} - public static function write_zint32($fp, $i){throw "I've not coded it yet Exception";} - public static function write_zint64($fp, $i){throw "I've not coded it yet Exception";} + public static function write_double($fp, $d){throw new Exception("I've not coded it yet Exception");} + public static function write_float ($fp, $f){throw new Exception("I've not coded it yet Exception");} + public static function write_uint64($fp, $i){throw new Exception("I've not coded it yet Exception");} + public static function write_int64 ($fp, $i){throw new Exception("I've not coded it yet Exception");} + public static function write_uint32($fp, $i){throw new Exception("I've not coded it yet Exception");} + public static function write_int32 ($fp, $i){throw new Exception("I've not coded it yet Exception");} + public static function write_zint32($fp, $i){throw new Exception("I've not coded it yet Exception");} + public static function write_zint64($fp, $i){throw new Exception("I've not coded it yet Exception");} /** * Seek past a varint diff --git a/Log_Autoload.php b/Log_Autoload.php index 75ffc47..940319d 100644 --- a/Log_Autoload.php +++ b/Log_Autoload.php @@ -9,8 +9,20 @@ function Aliyun_Log_PHP_Client_Autoload($className) { $classPath = explode('_', $className); if ($classPath[0] == 'Aliyun') { - if(count($classPath)>4) - $classPath = array_slice($classPath, 0, 4); + if(count($classPath)>5) + $classPath = array_slice($classPath, 0, 5); + if(strpos($className, 'Request') !== false){ + $lastPath = end($classPath); + array_pop($classPath); + array_push($classPath,'Request'); + array_push($classPath, $lastPath); + } + if(strpos($className, 'Response') !== false){ + $lastPath = end($classPath); + array_pop($classPath); + array_push($classPath,'Response'); + array_push($classPath, $lastPath); + } $filePath = dirname(__FILE__) . '/' . implode('/', $classPath) . '.php'; if (file_exists($filePath)) require_once($filePath); diff --git a/sample/demo.php b/sample/demo.php new file mode 100644 index 0000000..68f800d --- /dev/null +++ b/sample/demo.php @@ -0,0 +1,86 @@ + listShards($request); + print("
"); + foreach ($response ->getShardIds() as $shardId){ + print($shardId."
"); + } + + } catch (Exception $ex) { + print("exception code: ".$ex -> getErrorCode()); + } +} + +function putLogs(Aliyun_Log_Client $client, $project, $logstore) { + $topic = 'TestTopic'; + + $contents = array( // key-value pair + 'TestKey'=>'TestContent', + 'message'=>'test log from '.' at '.date('m/d/Y h:i:s a', time()) + ); + $logItem = new Aliyun_Log_Models_LogItem(); + $logItem->setTime(time()); + $logItem->setContents($contents); + $logitems = array($logItem); + $request = new Aliyun_Log_Models_PutLogsRequest($project, $logstore, + $topic, "", $logitems); + + try { + $response = $client->putLogs($request); + print($response ->getRequestId()); + } catch (Aliyun_Log_Exception $ex) { + logVarDump($ex); + } catch (Exception $ex) { + logVarDump($ex); + } +} + +function getLogs(Aliyun_Log_Client $client, $project, $logstore) { + $topic = 'MainFlow'; + $from = time()-3600; + $to = time(); + $request = new Aliyun_Log_Models_GetLogsRequest($project, $logstore, $from, $to, $topic, '', 100, 0, False); + + try { + $response = $client->getLogs($request); + foreach($response -> getLogs() as $log) + { + print $log -> getTime()."\t"; + foreach($log -> getContents() as $key => $value){ + print $key.":".$value."
"; + } + print "\n"; + } + + } catch (Aliyun_Log_Exception $ex) { + logVarDump($ex); + } catch (Exception $ex) { + logVarDump($ex); + } +} + +$endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; +$accessKeyId = 'LTAIUbY1Pk7Ryf1P'; +$accessKey = '0oXZLJrFoRnlzVpDpopNVstd87bUWn'; +$project = 'ali-sls-sdk-test'; +$logstore = 'sls-test'; +$token = ""; + +$client = new Aliyun_Log_Client($endpoint, $accessKeyId, $accessKey,$token); +listShard($client,$project,$logstore); + +$logger = new Aliyun_Log_Logger($client, $project, $logstore); + +$logger->log(Aliyun_Log_Models_logLevel_LogLevel::info, 'something wrong with the inner info', 'MainFlow'); + +getLogs($client,$project,$logstore); \ No newline at end of file diff --git a/sample/sample.php b/sample/sample.php index 1789e48..1c243b1 100644 --- a/sample/sample.php +++ b/sample/sample.php @@ -21,11 +21,11 @@ function putLogs(Aliyun_Log_Client $client, $project, $logstore) { try { $response = $client->putLogs($request); - var_dump($response); + logVarDump($response); } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); + logVarDump($ex); } catch (Exception $ex) { - var_dump($ex); + logVarDump($ex); } } @@ -33,11 +33,11 @@ function listLogstores(Aliyun_Log_Client $client, $project) { try{ $request = new Aliyun_Log_Models_ListLogstoresRequest($project); $response = $client->listLogstores($request); - var_dump($response); + logVarDump($response); } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); + logVarDump($ex); } catch (Exception $ex) { - var_dump($ex); + logVarDump($ex); } } @@ -47,11 +47,11 @@ function listTopics(Aliyun_Log_Client $client, $project, $logstore) { try { $response = $client->listTopics($request); - var_dump($response); + logVarDump($response); } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); + logVarDump($ex); } catch (Exception $ex) { - var_dump($ex); + logVarDump($ex); } } @@ -73,9 +73,9 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { } } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); + logVarDump($ex); } catch (Exception $ex) { - var_dump($ex); + logVarDump($ex); } } @@ -87,11 +87,11 @@ function getHistograms(Aliyun_Log_Client $client, $project, $logstore) { try { $response = $client->getHistograms($request); - var_dump($response); + logVarDump($response); } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); + logVarDump($ex); } catch (Exception $ex) { - var_dump($ex); + logVarDump($ex); } } function listShard(Aliyun_Log_Client $client,$project,$logstore){ @@ -99,13 +99,14 @@ function listShard(Aliyun_Log_Client $client,$project,$logstore){ try { $response = $client -> listShards($request); - var_dump($response); + logVarDump($response); } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); + logVarDump($ex); } catch (Exception $ex) { - var_dump($ex); + logVarDump($ex); } } + function batchGetLogs(Aliyun_Log_Client $client,$project,$logstore) { $listShardRequest = new Aliyun_Log_Models_ListShardsRequest($project,$logstore); @@ -119,7 +120,7 @@ function batchGetLogs(Aliyun_Log_Client $client,$project,$logstore) while(true) { $batchGetDataRequest = new Aliyun_Log_Models_BatchGetLogsRequest($project,$logstore,$shardId,$count,$cursor); - var_dump($batchGetDataRequest); + logVarDump($batchGetDataRequest); $response = $client -> batchGetLogs($batchGetDataRequest); if($cursor == $response -> getNextCursor()) { @@ -149,11 +150,11 @@ function deleteShard(Aliyun_Log_Client $client,$project,$logstore,$shardId) try { $response = $client -> deleteShard($request); - var_dump($response); + logVarDump($response); }catch (Aliyun_Log_Exception $ex) { - var_dump($ex); + logVarDump($ex); } catch (Exception $ex) { - var_dump($ex); + logVarDump($ex); } } function mergeShard(Aliyun_Log_Client $client,$project,$logstore,$shardId) @@ -162,11 +163,11 @@ function mergeShard(Aliyun_Log_Client $client,$project,$logstore,$shardId) try { $response = $client -> mergeShards($request); - var_dump($response); + logVarDump($response); }catch (Aliyun_Log_Exception $ex) { - var_dump($ex); + logVarDump($ex); } catch (Exception $ex) { - var_dump($ex); + logVarDump($ex); } } function splitShard(Aliyun_Log_Client $client,$project,$logstore,$shardId,$midHash) @@ -175,25 +176,36 @@ function splitShard(Aliyun_Log_Client $client,$project,$logstore,$shardId,$midHa try { $response = $client -> splitShard($request); - var_dump($response); + logVarDump($response); }catch (Aliyun_Log_Exception $ex) { - var_dump($ex); + logVarDump($ex); } catch (Exception $ex) { - var_dump($ex); + logVarDump($ex); } } -$endpoint = 'loginfo begin = ".get_class($expression)."
"; + var_dump($expression); + print "
loginfo end
"; +} + +/* + * please refer to aliyun sdk document for detail: + * http://help.aliyun-inc.com/internaldoc/detail/29074.html?spm=0.0.0.0.tqUNn5 + */ +$endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; +$accessKeyId = 'LTAIUbY1Pk7Ryf1P'; +$accessKey = '0oXZLJrFoRnlzVpDpopNVstd87bUWn'; +$project = 'ali-sls-sdk-test'; +$logstore = 'sls-test'; $token = ""; $client = new Aliyun_Log_Client($endpoint, $accessKeyId, $accessKey,$token); listShard($client,$project,$logstore); -mergeShard($client,$project,$logstore,82); -deleteShard($client,$project,$logstore,21); -splitShard($client,$project,$logstore,84,"0e000000000000000000000000000000"); +mergeShard($client,$project,$logstore,2); +deleteShard($client,$project,$logstore,2); +splitShard($client,$project,$logstore,2,"80000000000000000000000000000001"); putLogs($client, $project, $logstore); listShard($client,$project,$logstore); batchGetLogs($client,$project,$logstore); From 3c28da2a47e941716b8b689cd2f0392b6c6a8689 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Wed, 20 Dec 2017 14:15:45 +0800 Subject: [PATCH 02/19] =?UTF-8?q?sdk=E6=BA=90=E6=96=87=E4=BB=B6=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E8=B0=83=E6=95=B4=EF=BC=8C=E5=A2=9E=E5=8A=A0logger?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E8=B0=83=E7=94=A8=20-=20=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aliyun/Log/Logger.php | 19 +-- .../Log/Models/{ => Response}/QueriedLog.php | 144 +++++++++--------- sample/demo.php | 2 +- 3 files changed, 83 insertions(+), 82 deletions(-) rename Aliyun/Log/Models/{ => Response}/QueriedLog.php (95%) diff --git a/Aliyun/Log/Logger.php b/Aliyun/Log/Logger.php index d4f94ac..f7e1498 100644 --- a/Aliyun/Log/Logger.php +++ b/Aliyun/Log/Logger.php @@ -19,16 +19,10 @@ public function __construct($client, $project, $logstore) $this->project=$project; } - - private function getLocalIp(){ - $local_ip = getHostByName(php_uname('n')); - if(strlen($local_ip) == 0){ - $local_ip = getHostByName(getHostName()); - } - return $local_ip; - } - public function log($logLevel, $logMessage, $topic){ + if(!Aliyun_Log_Models_logLevel_LogLevel::isValidValue($logLevel)){ + throw new Exception('logLevel value is invalid!'); + } $ip = $this->getLocalIp(); $contents = array( // key-value pair 'time'=>date('m/d/Y h:i:s a', time()), @@ -51,4 +45,11 @@ public function log($logLevel, $logMessage, $topic){ } } + private function getLocalIp(){ + $local_ip = getHostByName(php_uname('n')); + if(strlen($local_ip) == 0){ + $local_ip = getHostByName(getHostName()); + } + return $local_ip; + } } \ No newline at end of file diff --git a/Aliyun/Log/Models/QueriedLog.php b/Aliyun/Log/Models/Response/QueriedLog.php similarity index 95% rename from Aliyun/Log/Models/QueriedLog.php rename to Aliyun/Log/Models/Response/QueriedLog.php index 81807c3..44f8be6 100644 --- a/Aliyun/Log/Models/QueriedLog.php +++ b/Aliyun/Log/Models/Response/QueriedLog.php @@ -1,72 +1,72 @@ -time = $time; - $this->source = $source; - $this->contents = $contents; // deep copy - } - - /** - * Get log source - * - * @return string log source - */ - public function getSource() { - return $this->source; - } - - /** - * Get log time - * - * @return integer log time - */ - public function getTime() { - return $this->time; - } - - /** - * Get log contents, content many key/value pair. - * - * @return array log contents - */ - public function getContents() { - return $this->contents; - } -} +time = $time; + $this->source = $source; + $this->contents = $contents; // deep copy + } + + /** + * Get log source + * + * @return string log source + */ + public function getSource() { + return $this->source; + } + + /** + * Get log time + * + * @return integer log time + */ + public function getTime() { + return $this->time; + } + + /** + * Get log contents, content many key/value pair. + * + * @return array log contents + */ + public function getContents() { + return $this->contents; + } +} diff --git a/sample/demo.php b/sample/demo.php index 68f800d..340c054 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -81,6 +81,6 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $logger = new Aliyun_Log_Logger($client, $project, $logstore); -$logger->log(Aliyun_Log_Models_logLevel_LogLevel::info, 'something wrong with the inner info', 'MainFlow'); +$logger->log('test', 'something wrong with the inner info', 'MainFlow'); getLogs($client,$project,$logstore); \ No newline at end of file From 91d5975e798393e975d937f9d5764377091e9a45 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Sat, 6 Jan 2018 14:49:00 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E6=8F=90=E4=BA=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aliyun/Log/Logger.php | 18 +++- Aliyun/Log/Models/LogBatch.php | 87 +++++++++++++++++++ .../Models/Response/ListShardsResponse.php | 1 - sample/demo.php | 14 ++- sample/sample.php | 8 +- 5 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 Aliyun/Log/Models/LogBatch.php diff --git a/Aliyun/Log/Logger.php b/Aliyun/Log/Logger.php index f7e1498..6805792 100644 --- a/Aliyun/Log/Logger.php +++ b/Aliyun/Log/Logger.php @@ -39,9 +39,23 @@ public function log($logLevel, $logMessage, $topic){ $response = $this->client->putLogs($request); print($response ->getRequestId()); } catch (Aliyun_Log_Exception $ex) { - logVarDump($ex); + var_dump($ex); } catch (Exception $ex) { - logVarDump($ex); + var_dump($ex); + } + } + + public function logBatch($logItems, $topic){ + $ip = $this->getLocalIp(); + try{ + $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, + $topic, $ip, $logItems); + $response = $this->client->putLogs($request); + print($response ->getRequestId()); + } catch (Aliyun_Log_Exception $ex) { + var_dump($ex); + } catch (Exception $ex) { + var_dump($ex); } } diff --git a/Aliyun/Log/Models/LogBatch.php b/Aliyun/Log/Models/LogBatch.php new file mode 100644 index 0000000..13b732b --- /dev/null +++ b/Aliyun/Log/Models/LogBatch.php @@ -0,0 +1,87 @@ +arraySize = $maxLogSize; + if(!is_integer($maxLogSize)){ + $this->arraySize = 5; + } + $this->logger = $logger; + if($sem_id == null || $shm_id == null){ + $MEMSIZE = 10240; + $SEMKEY = 22; + $SHMKEY = 33; + + $this->sem_id = sem_get($SEMKEY, 1); + sem_acquire($this->sem_id); + $this->shm_id = shm_attach($SHMKEY, $MEMSIZE); + if(shm_has_var($this->shm_id, 1)){ + shm_remove_var($this->shm_id, 1); + } + shm_put_var($this->shm_id, 1, $this->logItems); + } + } + + public function log($logMessage, $logLevel){ + $contents = array( // key-value pair + 'time'=>date('m/d/Y h:i:s a', time()), + 'message'=> $logMessage, + 'loglevel'=> $logLevel + ); + $logItem = new Aliyun_Log_Models_LogItem(); + $logItem->setTime(time()); + $logItem->setContents($contents); + printf($logMessage.'
'); + if(shm_has_var($this->shm_id, 1)){ + $logItems = shm_get_var($this->shm_id, 1); + array_push($logItems, $logItem); + + if(sizeof($logItems) == $this->arraySize){ + $this->logger->logBatch($logItems, 'MainFlow'); + $logItems = []; + } + + shm_remove_var($this->shm_id, 1); + shm_put_var($this->shm_id, 1, $logItems); + $this->logItems = $logItems; + } + } + + public function shareSem($shm_id){ + + if(shm_has_var($shm_id, 1)){ + $tmp = shm_get_var($shm_id, 1); + shm_put_var($shm_id, 1, "*,".$tmp); + }else{ + shm_put_var($shm_id, 1, "Variable 1"); + } + + $result = shm_get_var($shm_id, 1); + echo $result."
"; + } + + function __destruct() { + if(sizeof($this->logItems) > 0){ + $this->logger->logBatch($this->logItems, 'MainFlow'); + } + + sem_remove($this->sem_id); + shm_remove ($this->shm_id); + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Response/ListShardsResponse.php b/Aliyun/Log/Models/Response/ListShardsResponse.php index 8722328..71eea16 100644 --- a/Aliyun/Log/Models/Response/ListShardsResponse.php +++ b/Aliyun/Log/Models/Response/ListShardsResponse.php @@ -26,7 +26,6 @@ class Aliyun_Log_Models_ListShardsResponse extends Aliyun_Log_Models_Response { public function __construct($resp, $header) { parent::__construct ( $header ); foreach($resp as $key=>$value){ - var_dump($value); $this->shardIds[] = $value['shardID']; $this->shards[] = new Aliyun_Log_Models_Shard($value['shardID'],$value["status"],$value["inclusiveBeginKey"],$value["exclusiveEndKey"],$value["createTime"]); } diff --git a/sample/demo.php b/sample/demo.php index 340c054..1f52e13 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -70,8 +70,8 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { } $endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; -$accessKeyId = 'LTAIUbY1Pk7Ryf1P'; -$accessKey = '0oXZLJrFoRnlzVpDpopNVstd87bUWn'; +$accessKeyId = ''; +$accessKey = ''; $project = 'ali-sls-sdk-test'; $logstore = 'sls-test'; $token = ""; @@ -81,6 +81,12 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $logger = new Aliyun_Log_Logger($client, $project, $logstore); -$logger->log('test', 'something wrong with the inner info', 'MainFlow'); +//$logger->log('test', 'something wrong with the inner info', 'MainFlow'); +$batchLogger = new Aliyun_Log_Models_LogBatch(25, $logger); + +for($i = 1; $i <= 133; $i++){ + $batchLogger->log('something wrong with the inner info '.$i,'info'); +} + +getLogs($client,$project,$logstore); -getLogs($client,$project,$logstore); \ No newline at end of file diff --git a/sample/sample.php b/sample/sample.php index 1c243b1..469931d 100644 --- a/sample/sample.php +++ b/sample/sample.php @@ -195,10 +195,10 @@ function logVarDump($expression){ * http://help.aliyun-inc.com/internaldoc/detail/29074.html?spm=0.0.0.0.tqUNn5 */ $endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; -$accessKeyId = 'LTAIUbY1Pk7Ryf1P'; -$accessKey = '0oXZLJrFoRnlzVpDpopNVstd87bUWn'; -$project = 'ali-sls-sdk-test'; -$logstore = 'sls-test'; +$accessKeyId = ''; +$accessKey = ''; +$project = ''; +$logstore = ''; $token = ""; $client = new Aliyun_Log_Client($endpoint, $accessKeyId, $accessKey,$token); From 28a4487b5eb4d38f9d6d8f8d00289134ea18dfbe Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Mon, 8 Jan 2018 15:13:01 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=8A=9F=E8=83=BD=E5=8E=BB=E6=8E=89=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E9=94=81=EF=BC=8C=E5=A2=9E=E5=8A=A0flush=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aliyun/Log/Models/LogBatch.php | 80 ++++++++++++++++++++++------------ sample/demo.php | 4 +- 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/Aliyun/Log/Models/LogBatch.php b/Aliyun/Log/Models/LogBatch.php index 13b732b..7c70d82 100644 --- a/Aliyun/Log/Models/LogBatch.php +++ b/Aliyun/Log/Models/LogBatch.php @@ -4,6 +4,11 @@ * All rights reserved */ +/** + * Class Aliyun_Log_Models_LogBatch + * in some cases the http port is quite limited, so user could config a batch logger, + * which will cache some log and send to server in bulk + */ class Aliyun_Log_Models_LogBatch{ private $logItems = []; @@ -16,29 +21,49 @@ class Aliyun_Log_Models_LogBatch{ private $shm_id; - public function __construct($maxLogSize, Aliyun_Log_Logger $logger, $sem_id = null, $shm_id = null) + private $topic; + + private $waitTime; + + private $previousLogTime; + + public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = null, $cacheLogWaitTime = null) { - $this->arraySize = $maxLogSize; - if(!is_integer($maxLogSize)){ - $this->arraySize = 5; + if(NULL === $cacheLogCount || !is_integer($cacheLogCount)){ + $this->arraySize = 100; + }else{ + $this->arraySize = $cacheLogCount; } + + if(NULL === $cacheLogWaitTime || !is_integer($cacheLogWaitTime)){ + $this->waitTime = 5; + }else{ + $this->waitTime = $cacheLogWaitTime; + } + $this->logger = $logger; - if($sem_id == null || $shm_id == null){ - $MEMSIZE = 10240; - $SEMKEY = 22; - $SHMKEY = 33; - - $this->sem_id = sem_get($SEMKEY, 1); - sem_acquire($this->sem_id); - $this->shm_id = shm_attach($SHMKEY, $MEMSIZE); - if(shm_has_var($this->shm_id, 1)){ - shm_remove_var($this->shm_id, 1); - } - shm_put_var($this->shm_id, 1, $this->logItems); + $this->topic = $topic; + + $MEMSIZE = 10240; + $SEMKEY = 22 + time(); + $SHMKEY = 33 + time(); + + $this->sem_id = sem_get($SEMKEY, 1); + //sem_acquire($this->sem_id); + $this->shm_id = shm_attach($SHMKEY, $MEMSIZE); + if(shm_has_var($this->shm_id, 1)){ + shm_remove_var($this->shm_id, 1); } + shm_put_var($this->shm_id, 1, $this->logItems); + } public function log($logMessage, $logLevel){ + $prevoidCallTime = $this->previousLogTime; + if(NULL === $prevoidCallTime){ + $prevoidCallTime = 0; + } + $this->previousLogTime = time(); $contents = array( // key-value pair 'time'=>date('m/d/Y h:i:s a', time()), 'message'=> $logMessage, @@ -52,8 +77,8 @@ public function log($logMessage, $logLevel){ $logItems = shm_get_var($this->shm_id, 1); array_push($logItems, $logItem); - if(sizeof($logItems) == $this->arraySize){ - $this->logger->logBatch($logItems, 'MainFlow'); + if((sizeof($logItems) == $this->arraySize) || ($this->previousLogTime - $prevoidCallTime > 5)){ + $this->logger->logBatch($logItems, $this->topic); $logItems = []; } @@ -63,22 +88,21 @@ public function log($logMessage, $logLevel){ } } - public function shareSem($shm_id){ + private function batchSentLog($logItems){ - if(shm_has_var($shm_id, 1)){ - $tmp = shm_get_var($shm_id, 1); - shm_put_var($shm_id, 1, "*,".$tmp); - }else{ - shm_put_var($shm_id, 1, "Variable 1"); - } + } - $result = shm_get_var($shm_id, 1); - echo $result."
"; + public function logFlush(){ + if(sizeof($this->logItems) > 0){ + $this->logger->logBatch($this->logItems, $this->topic); + $this->logItems = []; + } + shm_remove_var($this->shm_id, 1); } function __destruct() { if(sizeof($this->logItems) > 0){ - $this->logger->logBatch($this->logItems, 'MainFlow'); + $this->logger->logBatch($this->logItems, $this->topic); } sem_remove($this->sem_id); diff --git a/sample/demo.php b/sample/demo.php index 1f52e13..e937cbd 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -82,9 +82,9 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $logger = new Aliyun_Log_Logger($client, $project, $logstore); //$logger->log('test', 'something wrong with the inner info', 'MainFlow'); -$batchLogger = new Aliyun_Log_Models_LogBatch(25, $logger); +$batchLogger = new Aliyun_Log_Models_LogBatch( $logger,'MainFlow'); -for($i = 1; $i <= 133; $i++){ +for($i = 1; $i <= 9; $i++){ $batchLogger->log('something wrong with the inner info '.$i,'info'); } From 45cedf288ed10f99990cf3bbaa148feee9f10194 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Tue, 16 Jan 2018 16:34:27 +0800 Subject: [PATCH 05/19] =?UTF-8?q?1.=20=E5=A2=9E=E5=8A=A0shipper=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=8C=85=E6=8B=AC=E5=A2=9E?= =?UTF-8?q?=E5=88=A0=E6=94=B9=E6=9F=A5=E5=8F=8AshipperTask=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=9F=A5=E8=AF=A2=E5=92=8C=E9=87=8D=E8=AF=95=202.=20b?= =?UTF-8?q?ug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aliyun/Log/Client.php | 156 +++++++++++++++- Aliyun/Log/Logger.php | 2 - Aliyun/Log/Models/LogBatch.php | 29 ++- Aliyun/Log/Models/OssShipperConfig.php | 166 ++++++++++++++++++ Aliyun/Log/Models/OssShipperCsvStorage.php | 107 +++++++++++ Aliyun/Log/Models/OssShipperJsonStorage.php | 12 ++ .../Log/Models/OssShipperParquetStorage.php | 33 ++++ Aliyun/Log/Models/OssShipperStorage.php | 27 +++ .../Models/Request/CreateShipperRequest.php | 94 ++++++++++ .../Models/Request/DeleteShipperRequest.php | 53 ++++++ .../Request/GetShipperConfigRequest.php | 53 ++++++ .../Models/Request/GetShipperTasksRequest.php | 146 +++++++++++++++ .../Log/Models/Request/ListShipperRequest.php | 37 ++++ .../Request/RetryShipperTasksRequest.php | 70 ++++++++ .../Models/Request/UpdateShipperRequest.php | 89 ++++++++++ .../Models/Response/CreateShipperResponse.php | 22 +++ .../Models/Response/DeleteShipperResponse.php | 22 +++ .../Response/GetShipperConfigResponse.php | 81 +++++++++ .../Response/GetShipperTasksResponse.php | 97 ++++++++++ .../Models/Response/ListShipperResponse.php | 78 ++++++++ .../Response/RetryShipperTasksResponse.php | 22 +++ .../Models/Response/UpdateShipperResponse.php | 22 +++ sample/demo.php | 109 +++++++++++- 23 files changed, 1507 insertions(+), 20 deletions(-) create mode 100644 Aliyun/Log/Models/OssShipperConfig.php create mode 100644 Aliyun/Log/Models/OssShipperCsvStorage.php create mode 100644 Aliyun/Log/Models/OssShipperJsonStorage.php create mode 100644 Aliyun/Log/Models/OssShipperParquetStorage.php create mode 100644 Aliyun/Log/Models/OssShipperStorage.php create mode 100644 Aliyun/Log/Models/Request/CreateShipperRequest.php create mode 100644 Aliyun/Log/Models/Request/DeleteShipperRequest.php create mode 100644 Aliyun/Log/Models/Request/GetShipperConfigRequest.php create mode 100644 Aliyun/Log/Models/Request/GetShipperTasksRequest.php create mode 100644 Aliyun/Log/Models/Request/ListShipperRequest.php create mode 100644 Aliyun/Log/Models/Request/RetryShipperTasksRequest.php create mode 100644 Aliyun/Log/Models/Request/UpdateShipperRequest.php create mode 100644 Aliyun/Log/Models/Response/CreateShipperResponse.php create mode 100644 Aliyun/Log/Models/Response/DeleteShipperResponse.php create mode 100644 Aliyun/Log/Models/Response/GetShipperConfigResponse.php create mode 100644 Aliyun/Log/Models/Response/GetShipperTasksResponse.php create mode 100644 Aliyun/Log/Models/Response/ListShipperResponse.php create mode 100644 Aliyun/Log/Models/Response/RetryShipperTasksResponse.php create mode 100644 Aliyun/Log/Models/Response/UpdateShipperResponse.php diff --git a/Aliyun/Log/Client.php b/Aliyun/Log/Client.php index 0cb8b0f..adaa36e 100644 --- a/Aliyun/Log/Client.php +++ b/Aliyun/Log/Client.php @@ -280,6 +280,159 @@ public function putLogs(Aliyun_Log_Models_PutLogsRequest $request) { return new Aliyun_Log_Models_PutLogsResponse ( $header ); } + /** + * create shipper service + * @param Aliyun_Log_Models_CreateShipperRequest $request + * return Aliyun_Log_Models_CreateShipperResponse + */ + public function createShipper(Aliyun_Log_Models_CreateShipperRequest $request){ + $headers = array(); + $params = array(); + $resource = "/logstores/".$request->getLogStore()."/shipper"; + $project = $request->getProject () !== null ? $request->getProject () : ''; + $headers["Content-Type"] = "application/json"; + + $body = array( + "shipperName" => $request->getShipperName(), + "targetType" => $request->getTargetType(), + "targetConfiguration" => $request->getTargetConfigration() + ); + $body_str = json_encode($body); + $headers["x-log-bodyrawsize"] = strlen($body_str); + list($resp, $header) = $this->send("POST", $project,$body_str,$resource,$params,$headers); + $requestId = isset($header['x-log-requestid']) ? $header ['x-log-requestid'] : ''; + $resp = $this->parseToJson($resp, $requestId); + return new Aliyun_Log_Models_CreateShipperResponse($resp, $header); + } + + /** + * create shipper service + * @param Aliyun_Log_Models_CreateShipperRequest $request + * return Aliyun_Log_Models_CreateShipperResponse + */ + public function updateShipper(Aliyun_Log_Models_UpdateShipperRequest $request){ + $headers = array(); + $params = array(); + $resource = "/logstores/".$request->getLogStore()."/shipper/".$request->getShipperName(); + $project = $request->getProject () !== null ? $request->getProject () : ''; + $headers["Content-Type"] = "application/json"; + + $body = array( + "shipperName" => $request->getShipperName(), + "targetType" => $request->getTargetType(), + "targetConfiguration" => $request->getTargetConfigration() + ); + $body_str = json_encode($body); + $headers["x-log-bodyrawsize"] = strlen($body_str); + list($resp, $header) = $this->send("PUT", $project,$body_str,$resource,$params,$headers); + $requestId = isset($header['x-log-requestid']) ? $header ['x-log-requestid'] : ''; + $resp = $this->parseToJson($resp, $requestId); + return new Aliyun_Log_Models_UpdateShipperResponse($resp, $header); + } + + /** + * get shipper tasks list + * @param Aliyun_Log_Models_CreateShipperRequest $request + * return Aliyun_Log_Models_CreateShipperResponse + */ + public function getShipperTasks(Aliyun_Log_Models_GetShipperTasksRequest $request){ + $headers = array(); + $params = array( + 'from' => $request->getStartTime(), + 'to' => $request->getEndTime(), + 'status' => $request->getStatusType(), + 'offset' => $request->getOffset(), + 'size' => $request->getSize() + ); + $resource = "/logstores/".$request->getLogStore()."/shipper/".$request->getShipperName()."/tasks"; + $project = $request->getProject () !== null ? $request->getProject () : ''; + $headers["x-log-bodyrawsize"] = 0; + $headers["Content-Type"] = "application/json"; + + list($resp, $header) = $this->send("GET", $project,null,$resource,$params,$headers); + $requestId = isset($header['x-log-requestid']) ? $header ['x-log-requestid'] : ''; + $resp = $this->parseToJson($resp, $requestId); + return new Aliyun_Log_Models_GetShipperTasksResponse($resp, $header); + } + + /** + * retry shipper tasks list + * @param Aliyun_Log_Models_CreateShipperRequest $request + * return Aliyun_Log_Models_CreateShipperResponse + */ + public function retryShipperTasks(Aliyun_Log_Models_RetryShipperTasksRequest $request){ + $headers = array(); + $params = array(); + $resource = "/logstores/".$request->getLogStore()."/shipper/".$request->getShipperName()."/tasks"; + $project = $request->getProject () !== null ? $request->getProject () : ''; + + $headers["Content-Type"] = "application/json"; + $body = $request->getTaskLists(); + $body_str = json_encode($body); + $headers["x-log-bodyrawsize"] = strlen($body_str); + list($resp, $header) = $this->send("PUT", $project,$body_str,$resource,$params,$headers); + $requestId = isset($header['x-log-requestid']) ? $header ['x-log-requestid'] : ''; + $resp = $this->parseToJson($resp, $requestId); + return new Aliyun_Log_Models_RetryShipperTasksResponse($resp, $header); + } + + /** + * delete shipper service + * @param Aliyun_Log_Models_DeleteShipperRequest $request + * return Aliyun_Log_Models_DeleteShipperResponse + */ + public function deleteShipper(Aliyun_Log_Models_DeleteShipperRequest $request){ + $headers = array(); + $params = array(); + $resource = "/logstores/".$request->getLogStore()."/shipper/".$request->getShipperName(); + $project = $request->getProject () !== null ? $request->getProject () : ''; + $headers["x-log-bodyrawsize"] = 0; + $headers["Content-Type"] = "application/json"; + + list($resp, $header) = $this->send("DELETE", $project,null,$resource,$params,$headers); + $requestId = isset($header['x-log-requestid']) ? $header ['x-log-requestid'] : ''; + $resp = $this->parseToJson($resp, $requestId); + return new Aliyun_Log_Models_DeleteShipperResponse($resp, $header); + } + + /** + * get shipper config service + * @param Aliyun_Log_Models_DeleteShipperRequest $request + * return Aliyun_Log_Models_DeleteShipperResponse + */ + public function getShipperConfig(Aliyun_Log_Models_GetShipperConfigRequest $request){ + $headers = array(); + $params = array(); + $resource = "/logstores/".$request->getLogStore()."/shipper/".$request->getShipperName(); + $project = $request->getProject () !== null ? $request->getProject () : ''; + $headers["x-log-bodyrawsize"] = 0; + $headers["Content-Type"] = "application/json"; + + list($resp, $header) = $this->send("GET", $project,null,$resource,$params,$headers); + $requestId = isset($header['x-log-requestid']) ? $header ['x-log-requestid'] : ''; + $resp = $this->parseToJson($resp, $requestId); + return new Aliyun_Log_Models_GetShipperConfigResponse($resp, $header); + } + + /** + * list shipper service + * @param Aliyun_Log_Models_DeleteShipperRequest $request + * return Aliyun_Log_Models_DeleteShipperResponse + */ + public function listShipper(Aliyun_Log_Models_ListShipperRequest $request){ + $headers = array(); + $params = array(); + $resource = "/logstores/".$request->getLogStore()."/shipper"; + $project = $request->getProject () !== null ? $request->getProject () : ''; + $headers["x-log-bodyrawsize"] = 0; + $headers["Content-Type"] = "application/json"; + + list($resp, $header) = $this->send("GET", $project,null,$resource,$params,$headers); + $requestId = isset($header['x-log-requestid']) ? $header ['x-log-requestid'] : ''; + $resp = $this->parseToJson($resp, $requestId); + return new Aliyun_Log_Models_ListShipperResponse($resp, $header); + } + /** * create logstore * Unsuccessful opertaion will cause an Aliyun_Log_Exception. @@ -301,6 +454,7 @@ public function createLogstore(Aliyun_Log_Models_CreateLogstoreRequest $request) "shardCount" => (int)($request -> getShardCount()) ); $body_str = json_encode($body); + $headers["x-log-bodyrawsize"] = strlen($body_str); list($resp,$header) = $this -> send("POST",$project,$body_str,$resource,$params,$headers); $requestId = isset ( $header ['x-log-requestid'] ) ? $header ['x-log-requestid'] : ''; $resp = $this->parseToJson ( $resp, $requestId ); @@ -318,7 +472,6 @@ public function updateLogstore(Aliyun_Log_Models_UpdateLogstoreRequest $request) $headers = array (); $params = array (); $project = $request->getProject () !== null ? $request->getProject () : ''; - $headers["x-log-bodyrawsize"] = 0; $headers["Content-Type"] = "application/json"; $body = array( "logstoreName" => $request -> getLogstore(), @@ -327,6 +480,7 @@ public function updateLogstore(Aliyun_Log_Models_UpdateLogstoreRequest $request) ); $resource = '/logstores/'.$request -> getLogstore(); $body_str = json_encode($body); + $headers["x-log-bodyrawsize"] = strlen($body_str); list($resp,$header) = $this -> send("PUT",$project,$body_str,$resource,$params,$headers); $requestId = isset ( $header ['x-log-requestid'] ) ? $header ['x-log-requestid'] : ''; $resp = $this->parseToJson ( $resp, $requestId ); diff --git a/Aliyun/Log/Logger.php b/Aliyun/Log/Logger.php index 6805792..27f8838 100644 --- a/Aliyun/Log/Logger.php +++ b/Aliyun/Log/Logger.php @@ -37,7 +37,6 @@ public function log($logLevel, $logMessage, $topic){ $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, $topic, $ip, $logitems); $response = $this->client->putLogs($request); - print($response ->getRequestId()); } catch (Aliyun_Log_Exception $ex) { var_dump($ex); } catch (Exception $ex) { @@ -51,7 +50,6 @@ public function logBatch($logItems, $topic){ $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, $topic, $ip, $logItems); $response = $this->client->putLogs($request); - print($response ->getRequestId()); } catch (Aliyun_Log_Exception $ex) { var_dump($ex); } catch (Exception $ex) { diff --git a/Aliyun/Log/Models/LogBatch.php b/Aliyun/Log/Models/LogBatch.php index 7c70d82..d6affa5 100644 --- a/Aliyun/Log/Models/LogBatch.php +++ b/Aliyun/Log/Models/LogBatch.php @@ -30,7 +30,7 @@ class Aliyun_Log_Models_LogBatch{ public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = null, $cacheLogWaitTime = null) { if(NULL === $cacheLogCount || !is_integer($cacheLogCount)){ - $this->arraySize = 100; + $this->arraySize = 10; }else{ $this->arraySize = $cacheLogCount; } @@ -44,13 +44,13 @@ public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = $this->logger = $logger; $this->topic = $topic; - $MEMSIZE = 10240; - $SEMKEY = 22 + time(); - $SHMKEY = 33 + time(); + $time_stampe = time(); + $MEMSIZE = 5120; + $SEMKEY = $time_stampe; + $SHMKEY = $time_stampe+2233; - $this->sem_id = sem_get($SEMKEY, 1); - //sem_acquire($this->sem_id); - $this->shm_id = shm_attach($SHMKEY, $MEMSIZE); + $this->sem_id = sem_get($SEMKEY, 10); + $this->shm_id = shm_attach($SHMKEY, $MEMSIZE); if(shm_has_var($this->shm_id, 1)){ shm_remove_var($this->shm_id, 1); } @@ -59,9 +59,9 @@ public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = } public function log($logMessage, $logLevel){ - $prevoidCallTime = $this->previousLogTime; - if(NULL === $prevoidCallTime){ - $prevoidCallTime = 0; + $prevoisCallTime = $this->previousLogTime; + if(NULL === $prevoisCallTime){ + $prevoisCallTime = 0; } $this->previousLogTime = time(); $contents = array( // key-value pair @@ -77,7 +77,8 @@ public function log($logMessage, $logLevel){ $logItems = shm_get_var($this->shm_id, 1); array_push($logItems, $logItem); - if((sizeof($logItems) == $this->arraySize) || ($this->previousLogTime - $prevoidCallTime > 5)){ + if((sizeof($logItems) == $this->arraySize || $this->previousLogTime - $prevoisCallTime > 5000) + && $prevoisCallTime > 0){ $this->logger->logBatch($logItems, $this->topic); $logItems = []; } @@ -88,10 +89,6 @@ public function log($logMessage, $logLevel){ } } - private function batchSentLog($logItems){ - - } - public function logFlush(){ if(sizeof($this->logItems) > 0){ $this->logger->logBatch($this->logItems, $this->topic); @@ -106,6 +103,6 @@ function __destruct() { } sem_remove($this->sem_id); - shm_remove ($this->shm_id); + shm_remove($this->shm_id); } } \ No newline at end of file diff --git a/Aliyun/Log/Models/OssShipperConfig.php b/Aliyun/Log/Models/OssShipperConfig.php new file mode 100644 index 0000000..916bc7e --- /dev/null +++ b/Aliyun/Log/Models/OssShipperConfig.php @@ -0,0 +1,166 @@ +roleArn; + } + + /** + * @param mixed $roleArn + */ + public function setRoleArn($roleArn) + { + $this->roleArn = $roleArn; + } + + /** + * @return mixed + */ + public function getPathFormat() + { + return $this->pathFormat; + } + + /** + * @param mixed $pathFormat + */ + public function setPathFormat($pathFormat) + { + $this->pathFormat = $pathFormat; + } + + /** + * @return mixed + */ + public function getStorage() + { + return $this->storage; + } + + /** + * @param mixed $storage + */ + public function setStorage($storage) + { + $this->storage = $storage; + } + + /** + * @return mixed + */ + public function getOssBucket() + { + return $this->ossBucket; + } + + /** + * @param mixed $ossBucket + */ + public function setOssBucket($ossBucket) + { + $this->ossBucket = $ossBucket; + } + + /** + * @return mixed + */ + public function getOssPrefix() + { + return $this->ossPrefix; + } + + /** + * @param mixed $ossPrefix + */ + public function setOssPrefix($ossPrefix) + { + $this->ossPrefix = $ossPrefix; + } + + /** + * @return mixed + */ + public function getBufferInterval() + { + return $this->bufferInterval; + } + + /** + * @param mixed $bufferInterval + */ + public function setBufferInterval($bufferInterval) + { + $this->bufferInterval = $bufferInterval; + } + + /** + * @return mixed + */ + public function getBufferSize() + { + return $this->bufferSize; + } + + /** + * @param mixed $bufferSize + */ + public function setBufferSize($bufferSize) + { + if($bufferSize > 256 || $bufferSize < 5){ + throw new Exception("buffSize is not valide, must between 5 and 256"); + } + $this->bufferSize = $bufferSize; + } + + /** + * @return mixed + */ + public function getCompressType() + { + return $this->compressType; + } + + /** + * @param mixed $compressType + */ + public function setCompressType($compressType) + { + $this->compressType = $compressType; + } + + + public function to_json_object() { + $json = array( + 'ossBucket' => $this->ossBucket, + 'ossPrefix' => $this->ossPrefix, + 'bufferInterval' => $this->bufferInterval, + 'bufferSize' => $this->bufferSize, + 'compressType' => $this->compressType, + 'roleArn' => $this->roleArn, + 'pathFormat' => $this->pathFormat, + 'storage' => $this->storage->to_json_object() + ); + if($this->storage->getFormat() == 'json'){ + unset($json['storage']); + } + return $json; + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/OssShipperCsvStorage.php b/Aliyun/Log/Models/OssShipperCsvStorage.php new file mode 100644 index 0000000..1c8af91 --- /dev/null +++ b/Aliyun/Log/Models/OssShipperCsvStorage.php @@ -0,0 +1,107 @@ +columns; + } + + /** + * @param mixed $columns + */ + public function setColumns($columns) + { + $this->columns = $columns; + } + + /** + * @return string + */ + public function getDelimiter(): string + { + return $this->delimiter; + } + + /** + * @param string $delimiter + */ + public function setDelimiter(string $delimiter) + { + $this->delimiter = $delimiter; + } + + /** + * @return string + */ + public function getQuote(): string + { + return $this->quote; + } + + /** + * @param string $quote + */ + public function setQuote(string $quote) + { + $this->quote = $quote; + } + + /** + * @return string + */ + public function getNullIdentifier(): string + { + return $this->nullIdentifier; + } + + /** + * @param string $nullIdentifier + */ + public function setNullIdentifier(string $nullIdentifier) + { + $this->nullIdentifier = $nullIdentifier; + } + + /** + * @return bool + */ + public function isHeader(): bool + { + return $this->header; + } + + /** + * @param bool $header + */ + public function setHeader(bool $header) + { + $this->header = $header; + } + + public function to_json_object(){ + $detail = array( + 'columns' => $this->columns, + 'delimiter' => $this->delimiter, + 'quote' => $this->quote, + 'nullIdentifier' => $this->nullIdentifier, + 'header' => $this->header + ); + return array( + 'detail' => $detail, + 'format' => parent::getFormat() + ); + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/OssShipperJsonStorage.php b/Aliyun/Log/Models/OssShipperJsonStorage.php new file mode 100644 index 0000000..1e2ef8e --- /dev/null +++ b/Aliyun/Log/Models/OssShipperJsonStorage.php @@ -0,0 +1,12 @@ +columns; + } + + /** + * @param mixed $columns + */ + public function setColumns($columns) + { + $this->columns = $columns; + } + + public function to_json_object(){ + $columns = array(); + return array( + 'detail' => $columns, + 'format' => 'parquet' + ); + } +} diff --git a/Aliyun/Log/Models/OssShipperStorage.php b/Aliyun/Log/Models/OssShipperStorage.php new file mode 100644 index 0000000..64f8d24 --- /dev/null +++ b/Aliyun/Log/Models/OssShipperStorage.php @@ -0,0 +1,27 @@ +format; + } + + /** + * @param mixed $format + */ + public function setFormat($format) + { + $this->format = $format; + } + + +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Request/CreateShipperRequest.php b/Aliyun/Log/Models/Request/CreateShipperRequest.php new file mode 100644 index 0000000..63af99d --- /dev/null +++ b/Aliyun/Log/Models/Request/CreateShipperRequest.php @@ -0,0 +1,94 @@ +logStore; + } + + /** + * @param mixed $logStore + */ + public function setLogStore($logStore) + { + $this->logStore = $logStore; + } + + /** + * Aliyun_Log_Models_CreateShipperRequest Constructor + * + */ + public function __construct($project) { + parent::__construct ( $project ); + } + + /** + * @return mixed + */ + public function getShipperName() + { + return $this->shipperName; + } + + /** + * @param mixed $shipperName + */ + public function setShipperName($shipperName) + { + $this->shipperName = $shipperName; + } + + /** + * @return mixed + */ + public function getTargetType() + { + return $this->targetType; + } + + /** + * @param mixed $targetType + */ + public function setTargetType($targetType) + { + $this->targetType = $targetType; + } + + /** + * @return mixed + */ + public function getTargetConfigration() + { + return $this->targetConfigration; + } + + /** + * @param mixed $targetConfigration + */ + public function setTargetConfigration($targetConfigration) + { + $this->targetConfigration = $targetConfigration; + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Request/DeleteShipperRequest.php b/Aliyun/Log/Models/Request/DeleteShipperRequest.php new file mode 100644 index 0000000..650f9ae --- /dev/null +++ b/Aliyun/Log/Models/Request/DeleteShipperRequest.php @@ -0,0 +1,53 @@ +logStore; + } + + /** + * @param mixed $logStore + */ + public function setLogStore($logStore) + { + $this->logStore = $logStore; + } + + + /** + * @return mixed + */ + public function getShipperName() + { + return $this->shipperName; + } + + /** + * @param mixed $shipperName + */ + public function setShipperName($shipperName) + { + $this->shipperName = $shipperName; + } + + /** + * Aliyun_Log_Models_CreateShipperRequest Constructor + * + */ + public function __construct($project) { + parent::__construct ( $project ); + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Request/GetShipperConfigRequest.php b/Aliyun/Log/Models/Request/GetShipperConfigRequest.php new file mode 100644 index 0000000..eafc01d --- /dev/null +++ b/Aliyun/Log/Models/Request/GetShipperConfigRequest.php @@ -0,0 +1,53 @@ +logStore; + } + + /** + * @param mixed $logStore + */ + public function setLogStore($logStore) + { + $this->logStore = $logStore; + } + + + /** + * @return mixed + */ + public function getShipperName() + { + return $this->shipperName; + } + + /** + * @param mixed $shipperName + */ + public function setShipperName($shipperName) + { + $this->shipperName = $shipperName; + } + + /** + * Aliyun_Log_Models_CreateShipperRequest Constructor + * + */ + public function __construct($project) { + parent::__construct ( $project ); + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Request/GetShipperTasksRequest.php b/Aliyun/Log/Models/Request/GetShipperTasksRequest.php new file mode 100644 index 0000000..b31f618 --- /dev/null +++ b/Aliyun/Log/Models/Request/GetShipperTasksRequest.php @@ -0,0 +1,146 @@ +startTime; + } + + /** + * @param mixed $startTime + */ + public function setStartTime($startTime) + { + $this->startTime = $startTime; + } + + /** + * @return mixed + */ + public function getEndTime() + { + return $this->endTime; + } + + /** + * @param mixed $endTime + */ + public function setEndTime($endTime) + { + $this->endTime = $endTime; + } + + /** + * @return + */ + public function getStatusType() + { + return $this->statusType; + } + + /** + * @param $statusType + */ + public function setStatusType($statusType) + { + $this->statusType = $statusType; + } + + /** + * @return mixed + */ + public function getOffset() + { + return $this->offset; + } + + /** + * @param mixed $offset + */ + public function setOffset($offset) + { + $this->offset = $offset; + } + + /** + * @return mixed + */ + public function getSize() + { + return $this->size; + } + + /** + * @param mixed $size + */ + public function setSize($size) + { + $this->size = $size; + } + + /** + * @return mixed + */ + public function getLogStore() + { + return $this->logStore; + } + + /** + * @param mixed $logStore + */ + public function setLogStore($logStore) + { + $this->logStore = $logStore; + } + + + /** + * @return mixed + */ + public function getShipperName() + { + return $this->shipperName; + } + + /** + * @param mixed $shipperName + */ + public function setShipperName($shipperName) + { + $this->shipperName = $shipperName; + } + + /** + * Aliyun_Log_Models_CreateShipperRequest Constructor + * + */ + public function __construct($project) { + parent::__construct ( $project ); + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Request/ListShipperRequest.php b/Aliyun/Log/Models/Request/ListShipperRequest.php new file mode 100644 index 0000000..03aa8be --- /dev/null +++ b/Aliyun/Log/Models/Request/ListShipperRequest.php @@ -0,0 +1,37 @@ +logStore; + } + + /** + * @param mixed $logStore + */ + public function setLogStore($logStore) + { + $this->logStore = $logStore; + } + + +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Request/RetryShipperTasksRequest.php b/Aliyun/Log/Models/Request/RetryShipperTasksRequest.php new file mode 100644 index 0000000..36343a9 --- /dev/null +++ b/Aliyun/Log/Models/Request/RetryShipperTasksRequest.php @@ -0,0 +1,70 @@ +taskLists; + } + + /** + * @param mixed $taskLists + */ + public function setTaskLists($taskLists) + { + $this->taskLists = $taskLists; + } + + /** + * @return mixed + */ + public function getLogStore() + { + return $this->logStore; + } + + /** + * @param mixed $logStore + */ + public function setLogStore($logStore) + { + $this->logStore = $logStore; + } + + + /** + * @return mixed + */ + public function getShipperName() + { + return $this->shipperName; + } + + /** + * @param mixed $shipperName + */ + public function setShipperName($shipperName) + { + $this->shipperName = $shipperName; + } + + /** + * Aliyun_Log_Models_CreateShipperRequest Constructor + * + */ + public function __construct($project) { + parent::__construct ( $project ); + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Request/UpdateShipperRequest.php b/Aliyun/Log/Models/Request/UpdateShipperRequest.php new file mode 100644 index 0000000..fe687ed --- /dev/null +++ b/Aliyun/Log/Models/Request/UpdateShipperRequest.php @@ -0,0 +1,89 @@ +logStore; + } + + /** + * @param mixed $logStore + */ + public function setLogStore($logStore) + { + $this->logStore = $logStore; + } + + /** + * Aliyun_Log_Models_CreateShipperRequest Constructor + * + */ + public function __construct($project) { + parent::__construct ( $project ); + } + + /** + * @return mixed + */ + public function getShipperName() + { + return $this->shipperName; + } + + /** + * @param mixed $shipperName + */ + public function setShipperName($shipperName) + { + $this->shipperName = $shipperName; + } + + /** + * @return mixed + */ + public function getTargetType() + { + return $this->targetType; + } + + /** + * @param mixed $targetType + */ + public function setTargetType($targetType) + { + $this->targetType = $targetType; + } + + /** + * @return mixed + */ + public function getTargetConfigration() + { + return $this->targetConfigration; + } + + /** + * @param mixed $targetConfigration + */ + public function setTargetConfigration($targetConfigration) + { + $this->targetConfigration = $targetConfigration; + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Response/CreateShipperResponse.php b/Aliyun/Log/Models/Response/CreateShipperResponse.php new file mode 100644 index 0000000..ab9233e --- /dev/null +++ b/Aliyun/Log/Models/Response/CreateShipperResponse.php @@ -0,0 +1,22 @@ +shipperName; + } + + /** + * @param mixed $shipperName + */ + public function setShipperName($shipperName) + { + $this->shipperName = $shipperName; + } + + /** + * @return mixed + */ + public function getTargetType() + { + return $this->targetType; + } + + /** + * @param mixed $targetType + */ + public function setTargetType($targetType) + { + $this->targetType = $targetType; + } + + /** + * @return mixed + */ + public function getTargetConfigration() + { + return $this->targetConfigration; + } + + /** + * @param mixed $targetConfigration + */ + public function setTargetConfigration($targetConfigration) + { + $this->targetConfigration = $targetConfigration; + } + + + + /** + * Aliyun_Log_Models_GetShipperConfigResponse constructor + * + * @param array $resp + * GetLogs HTTP response body + * @param array $header + * GetLogs HTTP response header + */ + public function __construct($resp, $header) { + parent::__construct ( $header ); + $this->shipperName = $resp['shipperName']; + $this->targetConfigration = $resp['targetConfiguration']; + $this->targetType = $resp['targetType']; + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Response/GetShipperTasksResponse.php b/Aliyun/Log/Models/Response/GetShipperTasksResponse.php new file mode 100644 index 0000000..bb2f7ba --- /dev/null +++ b/Aliyun/Log/Models/Response/GetShipperTasksResponse.php @@ -0,0 +1,97 @@ +total = $resp['total']; + $this->count = $resp['count']; + $this->statistics = $resp['statistics']; + $this->tasks = $resp['tasks']; + } + + /** + * @return mixed + */ + public function getCount() + { + return $this->count; + } + + /** + * @param mixed $count + */ + public function setCount($count) + { + $this->count = $count; + } + + /** + * @return mixed + */ + public function getTotal() + { + return $this->total; + } + + /** + * @param mixed $total + */ + public function setTotal($total) + { + $this->total = $total; + } + + /** + * @return mixed + */ + public function getStatistics() + { + return $this->statistics; + } + + /** + * @param mixed $statistics + */ + public function setStatistics($statistics) + { + $this->statistics = $statistics; + } + + /** + * @return mixed + */ + public function getTasks() + { + return $this->tasks; + } + + /** + * @param mixed $tasks + */ + public function setTasks($tasks) + { + $this->tasks = $tasks; + } + + +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Response/ListShipperResponse.php b/Aliyun/Log/Models/Response/ListShipperResponse.php new file mode 100644 index 0000000..d147161 --- /dev/null +++ b/Aliyun/Log/Models/Response/ListShipperResponse.php @@ -0,0 +1,78 @@ +count; + } + + /** + * @param mixed $count + */ + public function setCount($count) + { + $this->count = $count; + } + + /** + * @return mixed + */ + public function getTotal() + { + return $this->total; + } + + /** + * @param mixed $total + */ + public function setTotal($total) + { + $this->total = $total; + } + + /** + * @return mixed + */ + public function getShippers() + { + return $this->shippers; + } + + /** + * @param mixed $shippers + */ + public function setShippers($shippers) + { + $this->shippers = $shippers; + } + + + /** + * Aliyun_Log_Models_ListShipperResponse constructor + * + * @param array $resp + * GetLogs HTTP response body + * @param array $header + * GetLogs HTTP response header + */ + public function __construct($resp, $header) { + parent::__construct ( $header ); + $this->count = $resp['count']; + $this->total = $resp['total']; + $this->shippers = $resp['shipper']; + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/Response/RetryShipperTasksResponse.php b/Aliyun/Log/Models/Response/RetryShipperTasksResponse.php new file mode 100644 index 0000000..a666b1a --- /dev/null +++ b/Aliyun/Log/Models/Response/RetryShipperTasksResponse.php @@ -0,0 +1,22 @@ +setShipperName('testjsonshipper'); +$deleteShipper->setLogStore($logstore); +try{ + $client->deleteShipper($deleteShipper); +}catch (Exception $ex){} + +$shipper = new Aliyun_Log_Models_CreateShipperRequest($project); +$shipper->setShipperName('testshipper'); +$shipper->setTargetType('oss'); +$shipper->setLogStore($logstore); + +$ossCsvStorage = new Aliyun_Log_Models_OssShipperCsvStorage(); +$ossCsvStorage->setColumns(array('__topic__', + 'alarm_count', + 'alarm_message', + 'alarm_type', + 'category', + 'project_name')); +$ossCsvStorage->setDelimiter(','); +$ossCsvStorage->setQuote('"'); +$ossCsvStorage->setHeader(false); +$ossCsvStorage->setNullIdentifier(''); +$ossCsvStorage->setFormat('csv'); + +$ossJsonStorage = new Aliyun_Log_Models_OssShipperJsonStorage(); +$ossJsonStorage->setFormat('json'); + +$ossConfig = new Aliyun_Log_Models_OssShipperConfig(); +$ossConfig->setOssBucket('sls-test-oss-shipper'); +$ossConfig->setOssPrefix('logtailalarm'); +$ossConfig->setBufferInterval(300); +$ossConfig->setBufferSize(5); +$ossConfig->setCompressType('none'); +$ossConfig->setRoleArn('acs:ram::1654218965343050:role/aliyunlogdefaultrole'); +$ossConfig->setStorage($ossCsvStorage); +$ossConfig->setPathFormat('%Y/%m/%d/%H'); + +$shipper->setTargetConfigration($ossConfig->to_json_object()); +try{ + $client->createShipper($shipper); +}catch (Exception $exception){ + var_dump($exception); +} + +$getShipperConfig = new Aliyun_Log_Models_GetShipperConfigRequest($project); +$getShipperConfig->setShipperName($shipper->getShipperName()); +$getShipperConfig->setLogStore($shipper->getLogStore()); +$getconfigResp = $client->getShipperConfig($getShipperConfig); +var_dump($getconfigResp); + +$listShipper = new Aliyun_Log_Models_ListShipperRequest($project); +$listShipper->setLogStore($shipper->getLogStore()); +$listShpperResp = $client->listShipper($listShipper); +var_dump($listShpperResp); + +$updateShipper = new Aliyun_Log_Models_UpdateShipperRequest($project); +$updateShipper->setShipperName('testshipper'); +$updateShipper->setTargetType('oss'); +$updateShipper->setLogStore($logstore); +$ossConfig->setBufferInterval(599); +$updateShipper->setTargetConfigration($ossConfig->to_json_object()); + +$updateShipperResp = $client->updateShipper($updateShipper); + +$deleteShipper = new Aliyun_Log_Models_DeleteShipperRequest($project); +$deleteShipper->setShipperName($shipper->getShipperName()); +$deleteShipper->setLogStore($shipper->getLogStore()); + +$client->deleteShipper($deleteShipper); + +$shipper->setShipperName('testjsonshipper'); +$ossConfig->setStorage($ossJsonStorage); +$shipper->setTargetConfigration($ossConfig->to_json_object()); +try{ + $client->createShipper($shipper); +}catch (Exception $exception){ + var_dump($exception); +} + +$getShipperTasks = new Aliyun_Log_Models_GetShipperTasksRequest($project); +$getShipperTasks->setShipperName('testjsonshipper'); +$getShipperTasks->setLogStore($logstore); +$getShipperTasks->setStartTime(time()-10000); +$getShipperTasks->setEndTime(time()); +$getShipperTasks->setStatusType('');//means all status +$getShipperTasks->setOffset(0); +$getShipperTasks->setSize(5); + +$tasks = $client->getShipperTasks($getShipperTasks); +var_dump(json_encode($tasks->getStatistics())); +var_dump(json_encode($tasks->getTasks())); + +$taskIdList = array(); +for($i=0, $size=count($tasks->getTasks());$i<$size;++$i){ + $taskId = $tasks->getTasks()[$i]['id']; + array_push($taskIdList, $taskId); +} + +$retryShipperTask = new Aliyun_Log_Models_RetryShipperTasksRequest($project); +$retryShipperTask->setShipperName('testjsonshipper'); +$retryShipperTask->setLogStore($logstore); +$retryShipperTask->setTaskLists($taskIdList); +$client->retryShipperTasks($retryShipperTask); From cab78ced664c83595ce1a58df842a9684d1a67e4 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Tue, 16 Jan 2018 16:38:41 +0800 Subject: [PATCH 06/19] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aliyun/Log/Client.php | 4 ++-- Aliyun/Log/Models/LogBatch.php | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Aliyun/Log/Client.php b/Aliyun/Log/Client.php index adaa36e..62b592a 100644 --- a/Aliyun/Log/Client.php +++ b/Aliyun/Log/Client.php @@ -331,7 +331,7 @@ public function updateShipper(Aliyun_Log_Models_UpdateShipperRequest $request){ } /** - * get shipper tasks list + * get shipper tasks list, max 48 hours duration supported * @param Aliyun_Log_Models_CreateShipperRequest $request * return Aliyun_Log_Models_CreateShipperResponse */ @@ -356,7 +356,7 @@ public function getShipperTasks(Aliyun_Log_Models_GetShipperTasksRequest $reques } /** - * retry shipper tasks list + * retry shipper tasks list by task ids * @param Aliyun_Log_Models_CreateShipperRequest $request * return Aliyun_Log_Models_CreateShipperResponse */ diff --git a/Aliyun/Log/Models/LogBatch.php b/Aliyun/Log/Models/LogBatch.php index d6affa5..f65f535 100644 --- a/Aliyun/Log/Models/LogBatch.php +++ b/Aliyun/Log/Models/LogBatch.php @@ -27,10 +27,17 @@ class Aliyun_Log_Models_LogBatch{ private $previousLogTime; + /** + * Aliyun_Log_Models_LogBatch constructor. + * @param Aliyun_Log_Logger $logger + * @param $topic + * @param null $cacheLogCount max log items limitation, by default it's 100 + * @param null $cacheLogWaitTime max thread waiting time, bydefault it's 5 seconds + */ public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = null, $cacheLogWaitTime = null) { if(NULL === $cacheLogCount || !is_integer($cacheLogCount)){ - $this->arraySize = 10; + $this->arraySize = 100; }else{ $this->arraySize = $cacheLogCount; } @@ -49,7 +56,7 @@ public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = $SEMKEY = $time_stampe; $SHMKEY = $time_stampe+2233; - $this->sem_id = sem_get($SEMKEY, 10); + $this->sem_id = sem_get($SEMKEY, 10); // support 10 processes run simultaneously $this->shm_id = shm_attach($SHMKEY, $MEMSIZE); if(shm_has_var($this->shm_id, 1)){ shm_remove_var($this->shm_id, 1); @@ -58,6 +65,11 @@ public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = } + /** + * log expected message with proper level + * @param $logMessage + * @param $logLevel + */ public function log($logMessage, $logLevel){ $prevoisCallTime = $this->previousLogTime; if(NULL === $prevoisCallTime){ @@ -89,6 +101,9 @@ public function log($logMessage, $logLevel){ } } + /** + * manually flush all cached log to log server + */ public function logFlush(){ if(sizeof($this->logItems) > 0){ $this->logger->logBatch($this->logItems, $this->topic); From b5b354616f110f3686160e369bed7c4fb90b38ab Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Tue, 16 Jan 2018 16:50:11 +0800 Subject: [PATCH 07/19] add batch log --- Aliyun/Log/Models/LogBatch.php | 63 +++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/Aliyun/Log/Models/LogBatch.php b/Aliyun/Log/Models/LogBatch.php index f65f535..85dd8d1 100644 --- a/Aliyun/Log/Models/LogBatch.php +++ b/Aliyun/Log/Models/LogBatch.php @@ -71,33 +71,50 @@ public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = * @param $logLevel */ public function log($logMessage, $logLevel){ - $prevoisCallTime = $this->previousLogTime; - if(NULL === $prevoisCallTime){ - $prevoisCallTime = 0; + $previousCallTime = $this->previousLogTime; + if(NULL === $previousCallTime){ + $previousCallTime = 0; } $this->previousLogTime = time(); - $contents = array( // key-value pair - 'time'=>date('m/d/Y h:i:s a', time()), - 'message'=> $logMessage, - 'loglevel'=> $logLevel - ); - $logItem = new Aliyun_Log_Models_LogItem(); - $logItem->setTime(time()); - $logItem->setContents($contents); - printf($logMessage.'
'); - if(shm_has_var($this->shm_id, 1)){ - $logItems = shm_get_var($this->shm_id, 1); - array_push($logItems, $logItem); + if(is_array($logMessage)){ + $logItemTemps = array(); + foreach ($logMessage as &$logElement){ + $contents = array( // key-value pair + 'time'=>date('m/d/Y h:i:s a', time()), + 'message'=> $logElement, + 'loglevel'=> $logLevel + ); + $logItem = new Aliyun_Log_Models_LogItem(); + $logItem->setTime(time()); + $logItem->setContents($contents); + array_push($logItemTemps, $logItem); - if((sizeof($logItems) == $this->arraySize || $this->previousLogTime - $prevoisCallTime > 5000) - && $prevoisCallTime > 0){ - $this->logger->logBatch($logItems, $this->topic); - $logItems = []; - } - shm_remove_var($this->shm_id, 1); - shm_put_var($this->shm_id, 1, $logItems); - $this->logItems = $logItems; + } + $this->logger->logBatch($logItemTemps, $this->topic); + }else{ + $contents = array( // key-value pair + 'time'=>date('m/d/Y h:i:s a', time()), + 'message'=> $logMessage, + 'loglevel'=> $logLevel + ); + $logItem = new Aliyun_Log_Models_LogItem(); + $logItem->setTime(time()); + $logItem->setContents($contents); + if(shm_has_var($this->shm_id, 1)){ + $logItems = shm_get_var($this->shm_id, 1); + array_push($logItems, $logItem); + + if((sizeof($logItems) == $this->arraySize || $this->previousLogTime - $previousCallTime > 5000) + && $previousCallTime > 0){ + $this->logger->logBatch($logItems, $this->topic); + $logItems = []; + } + + shm_remove_var($this->shm_id, 1); + shm_put_var($this->shm_id, 1, $logItems); + $this->logItems = $logItems; + } } } From cd00f2a21563f385e7354dc262d6f6a104b3c35a Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Tue, 16 Jan 2018 20:41:19 +0800 Subject: [PATCH 08/19] =?UTF-8?q?parquet=20storage=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aliyun/Log/Client.php | 20 ++++----- .../Log/Models/OssShipperParquetStorage.php | 10 +++-- sample/demo.php | 44 +++++++++++++++++-- 3 files changed, 57 insertions(+), 17 deletions(-) diff --git a/Aliyun/Log/Client.php b/Aliyun/Log/Client.php index 62b592a..c345007 100644 --- a/Aliyun/Log/Client.php +++ b/Aliyun/Log/Client.php @@ -307,8 +307,8 @@ public function createShipper(Aliyun_Log_Models_CreateShipperRequest $request){ /** * create shipper service - * @param Aliyun_Log_Models_CreateShipperRequest $request - * return Aliyun_Log_Models_CreateShipperResponse + * @param Aliyun_Log_Models_UpdateShipperRequest $request + * return Aliyun_Log_Models_UpdateShipperResponse */ public function updateShipper(Aliyun_Log_Models_UpdateShipperRequest $request){ $headers = array(); @@ -332,8 +332,8 @@ public function updateShipper(Aliyun_Log_Models_UpdateShipperRequest $request){ /** * get shipper tasks list, max 48 hours duration supported - * @param Aliyun_Log_Models_CreateShipperRequest $request - * return Aliyun_Log_Models_CreateShipperResponse + * @param Aliyun_Log_Models_GetShipperTasksRequest $request + * return Aliyun_Log_Models_GetShipperTasksResponse */ public function getShipperTasks(Aliyun_Log_Models_GetShipperTasksRequest $request){ $headers = array(); @@ -357,8 +357,8 @@ public function getShipperTasks(Aliyun_Log_Models_GetShipperTasksRequest $reques /** * retry shipper tasks list by task ids - * @param Aliyun_Log_Models_CreateShipperRequest $request - * return Aliyun_Log_Models_CreateShipperResponse + * @param Aliyun_Log_Models_RetryShipperTasksRequest $request + * return Aliyun_Log_Models_RetryShipperTasksResponse */ public function retryShipperTasks(Aliyun_Log_Models_RetryShipperTasksRequest $request){ $headers = array(); @@ -397,8 +397,8 @@ public function deleteShipper(Aliyun_Log_Models_DeleteShipperRequest $request){ /** * get shipper config service - * @param Aliyun_Log_Models_DeleteShipperRequest $request - * return Aliyun_Log_Models_DeleteShipperResponse + * @param Aliyun_Log_Models_GetShipperConfigRequest $request + * return Aliyun_Log_Models_GetShipperConfigResponse */ public function getShipperConfig(Aliyun_Log_Models_GetShipperConfigRequest $request){ $headers = array(); @@ -416,8 +416,8 @@ public function getShipperConfig(Aliyun_Log_Models_GetShipperConfigRequest $requ /** * list shipper service - * @param Aliyun_Log_Models_DeleteShipperRequest $request - * return Aliyun_Log_Models_DeleteShipperResponse + * @param Aliyun_Log_Models_ListShipperRequest $request + * return Aliyun_Log_Models_ListShipperResponse */ public function listShipper(Aliyun_Log_Models_ListShipperRequest $request){ $headers = array(); diff --git a/Aliyun/Log/Models/OssShipperParquetStorage.php b/Aliyun/Log/Models/OssShipperParquetStorage.php index 0eb893e..309fd76 100644 --- a/Aliyun/Log/Models/OssShipperParquetStorage.php +++ b/Aliyun/Log/Models/OssShipperParquetStorage.php @@ -5,7 +5,7 @@ */ class Aliyun_Log_Models_OssShipperParquetStorage extends Aliyun_Log_Models_OssShipperStorage{ - private $columns; + private $columns; /** * @return mixed @@ -24,10 +24,12 @@ public function setColumns($columns) } public function to_json_object(){ - $columns = array(); + $detail = array( + 'columns' => $this->columns + ); return array( - 'detail' => $columns, - 'format' => 'parquet' + 'detail' => $detail, + 'format' => parent::getFormat() ); } } diff --git a/sample/demo.php b/sample/demo.php index 3bac5cd..4bde3f5 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -70,9 +70,9 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { } $endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; -$accessKeyId = ''; -$accessKey = ''; -$project = ''; +$accessKeyId = 'LTAIUbY1Pk7Ryf1P'; +$accessKey = '0oXZLJrFoRnlzVpDpopNVstd87bUWn'; +$project = 'ali-sls-sdk-test'; $logstore = 'sls-test'; $token = ""; @@ -166,6 +166,44 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $shipper->setShipperName('testjsonshipper'); $ossConfig->setStorage($ossJsonStorage); $shipper->setTargetConfigration($ossConfig->to_json_object()); +try{ + //$client->createShipper($shipper); +}catch (Exception $exception){ + var_dump($exception); +} + +$shipper->setShipperName('testparquetshipper'); +$ossParquetStorage = new Aliyun_Log_Models_OssShipperParquetStorage(); +$ossParquetStorage->setFormat('parquet'); +$ossParquetStorage->setColumns(array( + array( + 'name' => '__topic__', + 'type' => 'string' + ), + array( + 'name' => 'alarm_count', + 'type' => 'int32' + ), + array( + 'name' => 'alarm_message', + 'type' => 'string' + ), + array( + 'name' => 'alarm_type', + 'type' => 'string' + ), + array( + 'name' => 'is_active', + 'type' => 'boolean' + ), + array( + 'name' => 'project_name', + 'type' => 'string' + ), +)); +$ossConfig->setStorage($ossParquetStorage); +$shipper->setTargetConfigration($ossConfig->to_json_object()); + try{ $client->createShipper($shipper); }catch (Exception $exception){ From 35356849d5a6bcfd914088d2768c312ed58ba775 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Tue, 16 Jan 2018 20:43:01 +0800 Subject: [PATCH 09/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sample/demo.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sample/demo.php b/sample/demo.php index 4bde3f5..a3443f9 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -70,10 +70,10 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { } $endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; -$accessKeyId = 'LTAIUbY1Pk7Ryf1P'; -$accessKey = '0oXZLJrFoRnlzVpDpopNVstd87bUWn'; -$project = 'ali-sls-sdk-test'; -$logstore = 'sls-test'; +$accessKeyId = ''; +$accessKey = ''; +$project = ''; +$logstore = ''; $token = ""; $client = new Aliyun_Log_Client($endpoint, $accessKeyId, $accessKey,$token); @@ -91,7 +91,7 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { getLogs($client,$project,$logstore); $logger = null; - +//try delete the created shipper $deleteShipper = new Aliyun_Log_Models_DeleteShipperRequest($project); $deleteShipper->setShipperName('testjsonshipper'); $deleteShipper->setLogStore($logstore); @@ -99,6 +99,7 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $client->deleteShipper($deleteShipper); }catch (Exception $ex){} +//create shipper with csv storage $shipper = new Aliyun_Log_Models_CreateShipperRequest($project); $shipper->setShipperName('testshipper'); $shipper->setTargetType('oss'); @@ -163,6 +164,7 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $client->deleteShipper($deleteShipper); +//create shipper with json storage $shipper->setShipperName('testjsonshipper'); $ossConfig->setStorage($ossJsonStorage); $shipper->setTargetConfigration($ossConfig->to_json_object()); @@ -172,6 +174,7 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { var_dump($exception); } +//create shipper with parquet storage $shipper->setShipperName('testparquetshipper'); $ossParquetStorage = new Aliyun_Log_Models_OssShipperParquetStorage(); $ossParquetStorage->setFormat('parquet'); @@ -205,6 +208,7 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $shipper->setTargetConfigration($ossConfig->to_json_object()); try{ + $client->createShipper($shipper); }catch (Exception $exception){ var_dump($exception); From 6c0e7ff7cdef8d6e53c65d045acdadcb689bbf9f Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Tue, 16 Jan 2018 20:45:25 +0800 Subject: [PATCH 10/19] update demo --- sample/demo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sample/demo.php b/sample/demo.php index a3443f9..ada6254 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -87,7 +87,7 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { for($i = 1; $i <= 9; $i++){ $batchLogger->log('something wrong with the inner info '.$i,'info'); } - +$batchLogger->logFlush(); getLogs($client,$project,$logstore); $logger = null; From ef4f26d2c6c3ebabdad6fda13944a0777f9462d8 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Mon, 29 Jan 2018 14:15:09 +0800 Subject: [PATCH 11/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0loggerFactory=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aliyun/Log/Client.php | 2 +- Aliyun/Log/Logger.php | 42 +++++++++-- Aliyun/Log/LoggerFactory.php | 36 ++++++++++ Aliyun/Log/Models/LogLevel/LogLevel.php | 69 +++++++++++++++++++ Aliyun/Log/Models/logLevel/LogLevel.php | 42 ----------- .../{Models/LogBatch.php => SimpleLogger.php} | 48 +++---------- sample/demo.php | 20 ++++-- 7 files changed, 170 insertions(+), 89 deletions(-) create mode 100644 Aliyun/Log/LoggerFactory.php create mode 100644 Aliyun/Log/Models/LogLevel/LogLevel.php delete mode 100644 Aliyun/Log/Models/logLevel/LogLevel.php rename Aliyun/Log/{Models/LogBatch.php => SimpleLogger.php} (68%) diff --git a/Aliyun/Log/Client.php b/Aliyun/Log/Client.php index c345007..895eb7d 100644 --- a/Aliyun/Log/Client.php +++ b/Aliyun/Log/Client.php @@ -255,7 +255,7 @@ public function putLogs(Aliyun_Log_Models_PutLogsRequest $request) { $logGroup->addLogs ( $log ); } - $body = Aliyun_Log_Util::toBytes ( $logGroup ); + $body = Aliyun_Log_Util::toBytes( $logGroup ); unset ( $logGroup ); $bodySize = strlen ( $body ); diff --git a/Aliyun/Log/Logger.php b/Aliyun/Log/Logger.php index 27f8838..6f9c0e0 100644 --- a/Aliyun/Log/Logger.php +++ b/Aliyun/Log/Logger.php @@ -12,16 +12,19 @@ class Aliyun_Log_Logger{ protected $logstore; - public function __construct($client, $project, $logstore) + protected function __construct($client, $project, $logstore) { $this ->client = $client; $this->logstore=$logstore; $this->project=$project; } - public function log($logLevel, $logMessage, $topic){ - if(!Aliyun_Log_Models_logLevel_LogLevel::isValidValue($logLevel)){ - throw new Exception('logLevel value is invalid!'); + public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage, $topic){ + if(!$logLevel instanceof Aliyun_Log_Models_LogLevel_LogLevel){ + throw new Exception('LogLevel value is invalid!'); + } + if(is_array($logMessage)){ + throw new Exception('array is not supported in this function, please use logArray!'); } $ip = $this->getLocalIp(); $contents = array( // key-value pair @@ -44,6 +47,37 @@ public function log($logLevel, $logMessage, $topic){ } } + public function logArray(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage, $topic){ + if(!$logLevel instanceof Aliyun_Log_Models_LogLevel_LogLevel){ + throw new Exception('LogLevel value is invalid!'); + } + if(!is_array($logMessage)){ + throw new Exception('input message is not array, please use log!'); + } + $contents = array( // key-value pair + 'time'=>date('m/d/Y h:i:s a', time()) + ); + $ip = $this->getLocalIp(); + if(is_array($logMessage)){ + foreach ($logMessage as $key => $value) + $contents[$key] = $value; + } + + try { + $logItem = new Aliyun_Log_Models_LogItem(); + $logItem->setTime(time()); + $logItem->setContents($contents); + $logitems = array($logItem); + $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, + $topic, $ip, $logitems); + $response = $this->client->putLogs($request); + } catch (Aliyun_Log_Exception $ex) { + var_dump($ex); + } catch (Exception $ex) { + var_dump($ex); + } + } + public function logBatch($logItems, $topic){ $ip = $this->getLocalIp(); try{ diff --git a/Aliyun/Log/LoggerFactory.php b/Aliyun/Log/LoggerFactory.php new file mode 100644 index 0000000..6492d23 --- /dev/null +++ b/Aliyun/Log/LoggerFactory.php @@ -0,0 +1,36 @@ +level = $level; + } + + /** + * Compares two logger levels. + * + * @param LoggerLevels $other + * @return boolean + */ + public function equals($other) { + if($other instanceof Aliyun_Log_Models_LogLevel_LogLevel) { + if($this->level == $other->level) { + return true; + } + } else { + return false; + } + } + + public static function getLevelDebug(){ + if(!isset(self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::debug])){ + self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::debug] = new Aliyun_Log_Models_LogLevel_LogLevel('debug'); + } + return self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::debug]; + } + + public static function getLevelInfo(){ + if(!isset(self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::info])){ + self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::info] = new Aliyun_Log_Models_LogLevel_LogLevel('info'); + } + return self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::info]; + } + + public static function getLevelWarn(){ + if(!isset(self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::warn])){ + self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::warn] = new Aliyun_Log_Models_LogLevel_LogLevel('warn'); + } + return self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::warn]; + } + + public static function getLevelError(){ + if(!isset(self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::error])){ + self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::error] = new Aliyun_Log_Models_LogLevel_LogLevel('error'); + } + return self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::error]; + } +} \ No newline at end of file diff --git a/Aliyun/Log/Models/logLevel/LogLevel.php b/Aliyun/Log/Models/logLevel/LogLevel.php deleted file mode 100644 index d321dd6..0000000 --- a/Aliyun/Log/Models/logLevel/LogLevel.php +++ /dev/null @@ -1,42 +0,0 @@ -getConstants(); - } - return self::$constCacheArray[$calledClass]; - } - - public static function isValidName($name, $strict = false){ - $constans = self::getConstants(); - - if($strict){ - return array_key_exists($name, $constans); - } - - $keys = array_map('strtolower', array_keys($constans)); - return in_array(strtolower($name), $keys); - } - - public static function isValidValue($value, $strict = true){ - $values = array_values(self::getConstants()); - return in_array($value, $values, $strict); - } -} \ No newline at end of file diff --git a/Aliyun/Log/Models/LogBatch.php b/Aliyun/Log/SimpleLogger.php similarity index 68% rename from Aliyun/Log/Models/LogBatch.php rename to Aliyun/Log/SimpleLogger.php index 85dd8d1..390de8e 100644 --- a/Aliyun/Log/Models/LogBatch.php +++ b/Aliyun/Log/SimpleLogger.php @@ -9,7 +9,7 @@ * in some cases the http port is quite limited, so user could config a batch logger, * which will cache some log and send to server in bulk */ -class Aliyun_Log_Models_LogBatch{ +class Aliyun_Log_SimpleLogger extends Aliyun_Log_Logger { private $logItems = []; @@ -17,10 +17,6 @@ class Aliyun_Log_Models_LogBatch{ private $logger; - private $sem_id; - - private $shm_id; - private $topic; private $waitTime; @@ -34,10 +30,10 @@ class Aliyun_Log_Models_LogBatch{ * @param null $cacheLogCount max log items limitation, by default it's 100 * @param null $cacheLogWaitTime max thread waiting time, bydefault it's 5 seconds */ - public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = null, $cacheLogWaitTime = null) + protected function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = null, $cacheLogWaitTime = null) { if(NULL === $cacheLogCount || !is_integer($cacheLogCount)){ - $this->arraySize = 100; + $this->arraySize = 10; }else{ $this->arraySize = $cacheLogCount; } @@ -50,19 +46,6 @@ public function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = $this->logger = $logger; $this->topic = $topic; - - $time_stampe = time(); - $MEMSIZE = 5120; - $SEMKEY = $time_stampe; - $SHMKEY = $time_stampe+2233; - - $this->sem_id = sem_get($SEMKEY, 10); // support 10 processes run simultaneously - $this->shm_id = shm_attach($SHMKEY, $MEMSIZE); - if(shm_has_var($this->shm_id, 1)){ - shm_remove_var($this->shm_id, 1); - } - shm_put_var($this->shm_id, 1, $this->logItems); - } /** @@ -88,11 +71,10 @@ public function log($logMessage, $logLevel){ $logItem->setTime(time()); $logItem->setContents($contents); array_push($logItemTemps, $logItem); - - } $this->logger->logBatch($logItemTemps, $this->topic); }else{ + $logItems = $this->logItems; $contents = array( // key-value pair 'time'=>date('m/d/Y h:i:s a', time()), 'message'=> $logMessage, @@ -101,20 +83,16 @@ public function log($logMessage, $logLevel){ $logItem = new Aliyun_Log_Models_LogItem(); $logItem->setTime(time()); $logItem->setContents($contents); - if(shm_has_var($this->shm_id, 1)){ - $logItems = shm_get_var($this->shm_id, 1); - array_push($logItems, $logItem); - if((sizeof($logItems) == $this->arraySize || $this->previousLogTime - $previousCallTime > 5000) - && $previousCallTime > 0){ - $this->logger->logBatch($logItems, $this->topic); - $logItems = []; - } + array_push($logItems, $logItem); - shm_remove_var($this->shm_id, 1); - shm_put_var($this->shm_id, 1, $logItems); - $this->logItems = $logItems; + if((sizeof($logItems) == $this->arraySize + || $this->previousLogTime - $previousCallTime > 5000) + && $previousCallTime > 0){ + $this->logger->logBatch($logItems, $this->topic); + $logItems = []; } + $this->logItems = $logItems; } } @@ -126,15 +104,11 @@ public function logFlush(){ $this->logger->logBatch($this->logItems, $this->topic); $this->logItems = []; } - shm_remove_var($this->shm_id, 1); } function __destruct() { if(sizeof($this->logItems) > 0){ $this->logger->logBatch($this->logItems, $this->topic); } - - sem_remove($this->sem_id); - shm_remove($this->shm_id); } } \ No newline at end of file diff --git a/sample/demo.php b/sample/demo.php index ada6254..cce09e4 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -69,7 +69,8 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { } } -$endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; +// please update the configuration according your profile +$endpoint = ''; $accessKeyId = ''; $accessKey = ''; $project = ''; @@ -79,12 +80,20 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $client = new Aliyun_Log_Client($endpoint, $accessKeyId, $accessKey,$token); listShard($client,$project,$logstore); -$logger = new Aliyun_Log_Logger($client, $project, $logstore); +$logger = Aliyun_Log_LoggerFactory::getLogger($client, $project, $logstore); +$logMap = array( + 'message' => 'tet', + 'haha' => 'hehe' +); + +$logger->log(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG', 'MainFlow'); + +$logger->logArray(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),$logMap, 'MainFlow'); //$logger->log('test', 'something wrong with the inner info', 'MainFlow'); -$batchLogger = new Aliyun_Log_Models_LogBatch( $logger,'MainFlow'); +$batchLogger = Aliyun_Log_LoggerFactory::getSimpleLogger($client, $project, $logstore); -for($i = 1; $i <= 9; $i++){ +for($i = 1; $i <= 29; $i++){ $batchLogger->log('something wrong with the inner info '.$i,'info'); } $batchLogger->logFlush(); @@ -92,6 +101,7 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $logger = null; //try delete the created shipper +/* $deleteShipper = new Aliyun_Log_Models_DeleteShipperRequest($project); $deleteShipper->setShipperName('testjsonshipper'); $deleteShipper->setLogStore($logstore); @@ -238,4 +248,4 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $retryShipperTask->setLogStore($logstore); $retryShipperTask->setTaskLists($taskIdList); $client->retryShipperTasks($retryShipperTask); - +*/ From ec57d5ffb68e40ccbd3ea9499a262e5f21351e45 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Mon, 29 Jan 2018 15:30:39 +0800 Subject: [PATCH 12/19] bug fixed --- Aliyun/Log/Logger.php | 4 ++-- Aliyun/Log/Models/LogLevel/LogLevel.php | 23 +++++++++++++++++++++++ Aliyun/Log/SimpleLogger.php | 9 +++++---- sample/demo.php | 15 +++++++++------ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Aliyun/Log/Logger.php b/Aliyun/Log/Logger.php index 6f9c0e0..d07551e 100644 --- a/Aliyun/Log/Logger.php +++ b/Aliyun/Log/Logger.php @@ -30,7 +30,7 @@ public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage, $contents = array( // key-value pair 'time'=>date('m/d/Y h:i:s a', time()), 'message'=> $logMessage, - 'loglevel'=> $logLevel + 'loglevel'=> Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel) ); try { $logItem = new Aliyun_Log_Models_LogItem(); @@ -62,7 +62,7 @@ public function logArray(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMess foreach ($logMessage as $key => $value) $contents[$key] = $value; } - + $contents['logLevel'] = Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel); try { $logItem = new Aliyun_Log_Models_LogItem(); $logItem->setTime(time()); diff --git a/Aliyun/Log/Models/LogLevel/LogLevel.php b/Aliyun/Log/Models/LogLevel/LogLevel.php index 8d15591..86dfc04 100644 --- a/Aliyun/Log/Models/LogLevel/LogLevel.php +++ b/Aliyun/Log/Models/LogLevel/LogLevel.php @@ -66,4 +66,27 @@ public static function getLevelError(){ } return self::$constCacheArray[Aliyun_Log_Models_LogLevel_LogLevel::error]; } + + public static function getLevelStr(Aliyun_Log_Models_LogLevel_LogLevel $logLevel){ + + $logLevelStr = ''; + if(null === $logLevel){ + $logLevelStr = 'info'; + } + switch ($logLevel->level){ + case "error": + $logLevelStr= 'error'; + break; + case "warn": + $logLevelStr= 'warn'; + break; + case "info": + $logLevelStr= 'info'; + break; + case "debug": + $logLevelStr= 'debug'; + break; + } + return $logLevelStr; + } } \ No newline at end of file diff --git a/Aliyun/Log/SimpleLogger.php b/Aliyun/Log/SimpleLogger.php index 390de8e..91e79df 100644 --- a/Aliyun/Log/SimpleLogger.php +++ b/Aliyun/Log/SimpleLogger.php @@ -52,10 +52,11 @@ protected function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount * log expected message with proper level * @param $logMessage * @param $logLevel + * @param $topic should be null */ - public function log($logMessage, $logLevel){ + public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage, $topic = null){ $previousCallTime = $this->previousLogTime; - if(NULL === $previousCallTime){ + if(null === $previousCallTime){ $previousCallTime = 0; } $this->previousLogTime = time(); @@ -65,7 +66,7 @@ public function log($logMessage, $logLevel){ $contents = array( // key-value pair 'time'=>date('m/d/Y h:i:s a', time()), 'message'=> $logElement, - 'loglevel'=> $logLevel + 'loglevel'=> Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel) ); $logItem = new Aliyun_Log_Models_LogItem(); $logItem->setTime(time()); @@ -78,7 +79,7 @@ public function log($logMessage, $logLevel){ $contents = array( // key-value pair 'time'=>date('m/d/Y h:i:s a', time()), 'message'=> $logMessage, - 'loglevel'=> $logLevel + 'loglevel'=> Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel) ); $logItem = new Aliyun_Log_Models_LogItem(); $logItem->setTime(time()); diff --git a/sample/demo.php b/sample/demo.php index cce09e4..3b06ee8 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -70,11 +70,11 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { } // please update the configuration according your profile -$endpoint = ''; -$accessKeyId = ''; -$accessKey = ''; -$project = ''; -$logstore = ''; +$endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; +$accessKeyId = 'LTAIUbY1Pk7Ryf1P'; +$accessKey = '0oXZLJrFoRnlzVpDpopNVstd87bUWn'; +$project = 'ali-sls-sdk-test'; +$logstore = 'test'; $token = ""; $client = new Aliyun_Log_Client($endpoint, $accessKeyId, $accessKey,$token); @@ -88,13 +88,16 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $logger->log(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG', 'MainFlow'); +$logger2 = Aliyun_Log_LoggerFactory::getLogger($client, $project, $logstore); +$logger2->log(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG2222222', 'MainFlow'); + $logger->logArray(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),$logMap, 'MainFlow'); //$logger->log('test', 'something wrong with the inner info', 'MainFlow'); $batchLogger = Aliyun_Log_LoggerFactory::getSimpleLogger($client, $project, $logstore); for($i = 1; $i <= 29; $i++){ - $batchLogger->log('something wrong with the inner info '.$i,'info'); + $batchLogger->log(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'something wrong with the inner info '.$i); } $batchLogger->logFlush(); getLogs($client,$project,$logstore); From 67f88e2006198fc3b045bce0cc6efe520aa5e2fe Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Wed, 31 Jan 2018 13:47:59 +0800 Subject: [PATCH 13/19] =?UTF-8?q?logFactory=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aliyun/Log/Logger.php | 101 ----------------------------- Aliyun/Log/LoggerFactory.php | 31 ++++----- Aliyun/Log/SimpleLogger.php | 119 ++++++++++++++++++++++++++++++----- sample/demo.php | 14 ++--- 4 files changed, 128 insertions(+), 137 deletions(-) delete mode 100644 Aliyun/Log/Logger.php diff --git a/Aliyun/Log/Logger.php b/Aliyun/Log/Logger.php deleted file mode 100644 index d07551e..0000000 --- a/Aliyun/Log/Logger.php +++ /dev/null @@ -1,101 +0,0 @@ -client = $client; - $this->logstore=$logstore; - $this->project=$project; - } - - public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage, $topic){ - if(!$logLevel instanceof Aliyun_Log_Models_LogLevel_LogLevel){ - throw new Exception('LogLevel value is invalid!'); - } - if(is_array($logMessage)){ - throw new Exception('array is not supported in this function, please use logArray!'); - } - $ip = $this->getLocalIp(); - $contents = array( // key-value pair - 'time'=>date('m/d/Y h:i:s a', time()), - 'message'=> $logMessage, - 'loglevel'=> Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel) - ); - try { - $logItem = new Aliyun_Log_Models_LogItem(); - $logItem->setTime(time()); - $logItem->setContents($contents); - $logitems = array($logItem); - $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, - $topic, $ip, $logitems); - $response = $this->client->putLogs($request); - } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); - } catch (Exception $ex) { - var_dump($ex); - } - } - - public function logArray(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage, $topic){ - if(!$logLevel instanceof Aliyun_Log_Models_LogLevel_LogLevel){ - throw new Exception('LogLevel value is invalid!'); - } - if(!is_array($logMessage)){ - throw new Exception('input message is not array, please use log!'); - } - $contents = array( // key-value pair - 'time'=>date('m/d/Y h:i:s a', time()) - ); - $ip = $this->getLocalIp(); - if(is_array($logMessage)){ - foreach ($logMessage as $key => $value) - $contents[$key] = $value; - } - $contents['logLevel'] = Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel); - try { - $logItem = new Aliyun_Log_Models_LogItem(); - $logItem->setTime(time()); - $logItem->setContents($contents); - $logitems = array($logItem); - $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, - $topic, $ip, $logitems); - $response = $this->client->putLogs($request); - } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); - } catch (Exception $ex) { - var_dump($ex); - } - } - - public function logBatch($logItems, $topic){ - $ip = $this->getLocalIp(); - try{ - $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, - $topic, $ip, $logItems); - $response = $this->client->putLogs($request); - } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); - } catch (Exception $ex) { - var_dump($ex); - } - } - - private function getLocalIp(){ - $local_ip = getHostByName(php_uname('n')); - if(strlen($local_ip) == 0){ - $local_ip = getHostByName(getHostName()); - } - return $local_ip; - } -} \ No newline at end of file diff --git a/Aliyun/Log/LoggerFactory.php b/Aliyun/Log/LoggerFactory.php index 6492d23..348d690 100644 --- a/Aliyun/Log/LoggerFactory.php +++ b/Aliyun/Log/LoggerFactory.php @@ -4,26 +4,29 @@ * All rights reserved */ -class Aliyun_Log_LoggerFactory extends Aliyun_Log_SimpleLogger{ - protected static $instanceLogger = null; - protected static $instanceSimpleLogger = null; +/** + * Class Aliyun_Log_LoggerFactory + */ +class Aliyun_Log_LoggerFactory{ - public static function getLogger($client, $project, $logstore){ - if (!isset(static::$instanceLogger)) { - static::$instanceLogger = new Aliyun_Log_Logger($client, $project, $logstore); - } - return static::$instanceLogger; - } + private static $loggerMap = array(); - public static function getSimpleLogger($client, $project, $logstore, $topic=null){ + public static function getLogger($client, $project, $logstore, $topic = null){ + if($project === null || $project == ''){ + throw new Exception('project name is blank!'); + } + if($logstore === null || $logstore == ''){ + throw new Exception('logstore name is blank!'); + } if($topic === null){ $topic = 'MainFlow'; } - if (!isset(static::$instanceSimpleLogger)) { - $logger = new Aliyun_Log_Logger($client, $project, $logstore); - static::$instanceSimpleLogger = new Aliyun_Log_SimpleLogger($logger,$topic); + $loggerKey = $project.'#'.$logstore.'#'.$topic; + if (!array_key_exists($loggerKey, static::$loggerMap) || static::$loggerMap[$loggerKey] === null) { + $instanceSimpleLogger = new Aliyun_Log_SimpleLogger($client,$project,$logstore,$topic); + static::$loggerMap[$loggerKey] = $instanceSimpleLogger; } - return static::$instanceSimpleLogger; + return static::$loggerMap[$loggerKey]; } protected function __construct() diff --git a/Aliyun/Log/SimpleLogger.php b/Aliyun/Log/SimpleLogger.php index 91e79df..668d2f2 100644 --- a/Aliyun/Log/SimpleLogger.php +++ b/Aliyun/Log/SimpleLogger.php @@ -5,32 +5,37 @@ */ /** - * Class Aliyun_Log_Models_LogBatch - * in some cases the http port is quite limited, so user could config a batch logger, - * which will cache some log and send to server in bulk + * Class Aliyun_Log_SimpleLogger + * simple logger for submit log message */ -class Aliyun_Log_SimpleLogger extends Aliyun_Log_Logger { +class Aliyun_Log_SimpleLogger{ private $logItems = []; private $arraySize; - private $logger; - private $topic; private $waitTime; private $previousLogTime; + private $client; + + private $project; + + private $logstore; + /** * Aliyun_Log_Models_LogBatch constructor. - * @param Aliyun_Log_Logger $logger + * @param $client log client + * @param $project the corresponding project + * @param $logstore the logstore * @param $topic * @param null $cacheLogCount max log items limitation, by default it's 100 * @param null $cacheLogWaitTime max thread waiting time, bydefault it's 5 seconds */ - protected function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount = null, $cacheLogWaitTime = null) + public function __construct($client, $project, $logstore, $topic, $cacheLogCount = null, $cacheLogWaitTime = null) { if(NULL === $cacheLogCount || !is_integer($cacheLogCount)){ $this->arraySize = 10; @@ -43,8 +48,12 @@ protected function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount }else{ $this->waitTime = $cacheLogWaitTime; } - - $this->logger = $logger; + if($client == null || $project == null || $logstore == null){ + throw new Exception('the input parameter is invalid! create SimpleLogger failed!'); + } + $this->client = $client; + $this->project = $project; + $this->logstore = $logstore; $this->topic = $topic; } @@ -54,7 +63,7 @@ protected function __construct(Aliyun_Log_Logger $logger, $topic, $cacheLogCount * @param $logLevel * @param $topic should be null */ - public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage, $topic = null){ + public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage){ $previousCallTime = $this->previousLogTime; if(null === $previousCallTime){ $previousCallTime = 0; @@ -73,7 +82,7 @@ public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage, $ $logItem->setContents($contents); array_push($logItemTemps, $logItem); } - $this->logger->logBatch($logItemTemps, $this->topic); + $this->logBatch($logItemTemps, $this->topic); }else{ $logItems = $this->logItems; $contents = array( // key-value pair @@ -90,26 +99,106 @@ public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage, $ if((sizeof($logItems) == $this->arraySize || $this->previousLogTime - $previousCallTime > 5000) && $previousCallTime > 0){ - $this->logger->logBatch($logItems, $this->topic); + $this->logBatch($logItems, $this->topic); $logItems = []; } $this->logItems = $logItems; } } + public function logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ + if(!$logLevel instanceof Aliyun_Log_Models_LogLevel_LogLevel){ + throw new Exception('LogLevel value is invalid!'); + } + if(is_array($logMessage)){ + throw new Exception('array is not supported in this function, please use logArrayMessage!'); + } + $ip = $this->getLocalIp(); + $contents = array( // key-value pair + 'time'=>date('m/d/Y h:i:s a', time()), + 'message'=> $logMessage, + 'loglevel'=> Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel) + ); + try { + $logItem = new Aliyun_Log_Models_LogItem(); + $logItem->setTime(time()); + $logItem->setContents($contents); + $logitems = array($logItem); + $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, + $this->topic, $ip, $logitems); + $response = $this->client->putLogs($request); + } catch (Aliyun_Log_Exception $ex) { + var_dump($ex); + } catch (Exception $ex) { + var_dump($ex); + } + } + + public function logArrayMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ + if(!$logLevel instanceof Aliyun_Log_Models_LogLevel_LogLevel){ + throw new Exception('LogLevel value is invalid!'); + } + if(!is_array($logMessage)){ + throw new Exception('input message is not array, please use logSingleMessage!'); + } + $contents = array( // key-value pair + 'time'=>date('m/d/Y h:i:s a', time()) + ); + $ip = $this->getLocalIp(); + if(is_array($logMessage)){ + foreach ($logMessage as $key => $value) + $contents[$key] = $value; + } + $contents['logLevel'] = Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel); + try { + $logItem = new Aliyun_Log_Models_LogItem(); + $logItem->setTime(time()); + $logItem->setContents($contents); + $logitems = array($logItem); + $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, + $this->topic, $ip, $logitems); + $response = $this->client->putLogs($request); + } catch (Aliyun_Log_Exception $ex) { + var_dump($ex); + } catch (Exception $ex) { + var_dump($ex); + } + } + + private function getLocalIp(){ + $local_ip = getHostByName(php_uname('n')); + if(strlen($local_ip) == 0){ + $local_ip = getHostByName(getHostName()); + } + return $local_ip; + } + + private function logBatch($logItems, $topic){ + $ip = $this->getLocalIp(); + try{ + $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, + $topic, $ip, $logItems); + $response = $this->client->putLogs($request); + } catch (Aliyun_Log_Exception $ex) { + var_dump($ex); + } catch (Exception $ex) { + var_dump($ex); + } + } + /** * manually flush all cached log to log server */ public function logFlush(){ if(sizeof($this->logItems) > 0){ - $this->logger->logBatch($this->logItems, $this->topic); + $this->logBatch($this->logItems, $this->topic); $this->logItems = []; } } function __destruct() { if(sizeof($this->logItems) > 0){ - $this->logger->logBatch($this->logItems, $this->topic); + $this->logBatch($this->logItems, $this->topic); } } } \ No newline at end of file diff --git a/sample/demo.php b/sample/demo.php index 3b06ee8..db550cf 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -70,10 +70,10 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { } // please update the configuration according your profile -$endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; -$accessKeyId = 'LTAIUbY1Pk7Ryf1P'; -$accessKey = '0oXZLJrFoRnlzVpDpopNVstd87bUWn'; -$project = 'ali-sls-sdk-test'; +$endpoint = ''; +$accessKeyId = ''; +$accessKey = ''; +$project = ''; $logstore = 'test'; $token = ""; @@ -89,12 +89,12 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $logger->log(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG', 'MainFlow'); $logger2 = Aliyun_Log_LoggerFactory::getLogger($client, $project, $logstore); -$logger2->log(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG2222222', 'MainFlow'); +$logger2->logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG2222222', 'MainFlow'); -$logger->logArray(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),$logMap, 'MainFlow'); +$logger->logArrayMessage(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),$logMap, 'MainFlow'); //$logger->log('test', 'something wrong with the inner info', 'MainFlow'); -$batchLogger = Aliyun_Log_LoggerFactory::getSimpleLogger($client, $project, $logstore); +$batchLogger = Aliyun_Log_LoggerFactory::getLogger($client, $project, $logstore,'helloworld'); for($i = 1; $i <= 29; $i++){ $batchLogger->log(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'something wrong with the inner info '.$i); From 30ac7b1d40ad1cbe7d9a3f2ca5df4fb1f5c0c364 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Thu, 1 Feb 2018 20:04:05 +0800 Subject: [PATCH 14/19] =?UTF-8?q?code=20review=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aliyun/Log/LoggerFactory.php | 10 +++- Aliyun/Log/SimpleLogger.php | 107 ++++++++++++++++++++--------------- sample/demo.php | 29 +++++++--- 3 files changed, 92 insertions(+), 54 deletions(-) diff --git a/Aliyun/Log/LoggerFactory.php b/Aliyun/Log/LoggerFactory.php index 348d690..79e9121 100644 --- a/Aliyun/Log/LoggerFactory.php +++ b/Aliyun/Log/LoggerFactory.php @@ -18,7 +18,7 @@ public static function getLogger($client, $project, $logstore, $topic = null){ if($logstore === null || $logstore == ''){ throw new Exception('logstore name is blank!'); } - if($topic === null){ + if($topic === null || $topic === ''){ $topic = 'MainFlow'; } $loggerKey = $project.'#'.$logstore.'#'.$topic; @@ -36,4 +36,12 @@ protected function __construct() private function __clone() {} + + function __destruct() { + if(static::$loggerMap != null){ + foreach (static::$loggerMap as $innerLogger){ + $innerLogger->logFlush(); + } + } + } } \ No newline at end of file diff --git a/Aliyun/Log/SimpleLogger.php b/Aliyun/Log/SimpleLogger.php index 668d2f2..db2fad2 100644 --- a/Aliyun/Log/SimpleLogger.php +++ b/Aliyun/Log/SimpleLogger.php @@ -63,26 +63,14 @@ public function __construct($client, $project, $logstore, $topic, $cacheLogCount * @param $logLevel * @param $topic should be null */ - public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage){ + private function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage){ $previousCallTime = $this->previousLogTime; if(null === $previousCallTime){ $previousCallTime = 0; } $this->previousLogTime = time(); if(is_array($logMessage)){ - $logItemTemps = array(); - foreach ($logMessage as &$logElement){ - $contents = array( // key-value pair - 'time'=>date('m/d/Y h:i:s a', time()), - 'message'=> $logElement, - 'loglevel'=> Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel) - ); - $logItem = new Aliyun_Log_Models_LogItem(); - $logItem->setTime(time()); - $logItem->setContents($contents); - array_push($logItemTemps, $logItem); - } - $this->logBatch($logItemTemps, $this->topic); + throw new Exception('array is not supported in this function, please use logArrayMessage!'); }else{ $logItems = $this->logItems; $contents = array( // key-value pair @@ -106,6 +94,25 @@ public function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage){ } } + private function logItem($logItem){ + $previousCallTime = $this->previousLogTime; + if(null === $previousCallTime){ + $previousCallTime = 0; + } + $this->previousLogTime = time(); + $logItems = $this->logItems; + + array_push($logItems, $logItem); + + if((sizeof($logItems) == $this->arraySize + || $this->previousLogTime - $previousCallTime > 5000) + && $previousCallTime > 0){ + $this->logBatch($logItems, $this->topic); + $logItems = []; + } + $this->logItems = $logItems; + } + public function logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ if(!$logLevel instanceof Aliyun_Log_Models_LogLevel_LogLevel){ throw new Exception('LogLevel value is invalid!'); @@ -113,25 +120,7 @@ public function logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, if(is_array($logMessage)){ throw new Exception('array is not supported in this function, please use logArrayMessage!'); } - $ip = $this->getLocalIp(); - $contents = array( // key-value pair - 'time'=>date('m/d/Y h:i:s a', time()), - 'message'=> $logMessage, - 'loglevel'=> Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel) - ); - try { - $logItem = new Aliyun_Log_Models_LogItem(); - $logItem->setTime(time()); - $logItem->setContents($contents); - $logitems = array($logItem); - $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, - $this->topic, $ip, $logitems); - $response = $this->client->putLogs($request); - } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); - } catch (Exception $ex) { - var_dump($ex); - } + $this->log($logLevel, $logMessage); } public function logArrayMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ @@ -150,19 +139,45 @@ public function logArrayMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $ $contents[$key] = $value; } $contents['logLevel'] = Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel); - try { - $logItem = new Aliyun_Log_Models_LogItem(); - $logItem->setTime(time()); - $logItem->setContents($contents); - $logitems = array($logItem); - $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, - $this->topic, $ip, $logitems); - $response = $this->client->putLogs($request); - } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); - } catch (Exception $ex) { - var_dump($ex); - } + $logItem = new Aliyun_Log_Models_LogItem(); + $logItem->setTime(time()); + $logItem->setContents($contents); + + $this->logItem($logItem); + } + + public function info( $logMessage){ + $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(); + $this->logSingleMessage($logLevel, $logMessage); + } + public function debug($logMessage){ + $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelDebug(); + $this->logSingleMessage($logLevel, $logMessage); + } + public function warn($logMessage){ + $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelWarn(); + $this->logSingleMessage($logLevel, $logMessage); + } + public function error($logMessage){ + $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelError(); + $this->logSingleMessage($logLevel, $logMessage); + } + + public function infoArray($logMessage){ + $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(); + $this->logArrayMessage($logLevel, $logMessage); + } + public function debugArray($logMessage){ + $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelDebug(); + $this->logArrayMessage($logLevel, $logMessage); + } + public function warnArray($logMessage){ + $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelWarn(); + $this->logArrayMessage($logLevel, $logMessage); + } + public function errorArray( $logMessage){ + $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelError(); + $this->logArrayMessage($logLevel, $logMessage); } private function getLocalIp(){ diff --git a/sample/demo.php b/sample/demo.php index db550cf..4f0c118 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -70,10 +70,10 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { } // please update the configuration according your profile -$endpoint = ''; -$accessKeyId = ''; -$accessKey = ''; -$project = ''; +$endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; +$accessKeyId = 'LTAIUbY1Pk7Ryf1P'; +$accessKey = '0oXZLJrFoRnlzVpDpopNVstd87bUWn'; +$project = 'ali-sls-sdk-test'; $logstore = 'test'; $token = ""; @@ -86,7 +86,7 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { 'haha' => 'hehe' ); -$logger->log(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG', 'MainFlow'); +$logger->logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG'); $logger2 = Aliyun_Log_LoggerFactory::getLogger($client, $project, $logstore); $logger2->logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG2222222', 'MainFlow'); @@ -97,11 +97,26 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $batchLogger = Aliyun_Log_LoggerFactory::getLogger($client, $project, $logstore,'helloworld'); for($i = 1; $i <= 29; $i++){ - $batchLogger->log(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'something wrong with the inner info '.$i); + $batchLogger->logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'something wrong with the inner info '.$i); } $batchLogger->logFlush(); getLogs($client,$project,$logstore); -$logger = null; + +$logger2->info('test log message 000 info'); +$logger2->warn('test log message 000 warn'); +$logger2->error('test log message 000 error'); +$logger2->debug('test log message 000 debug'); + +$logMap['level'] = 'info'; +$logger2->infoArray($logMap); +$logMap['level'] = 'debug'; +$logger2->debugArray($logMap); +$logMap['level'] = 'warn'; +$logger2->warnArray($logMap); +$logMap['level'] = 'error'; +$logger2->errorArray($logMap); + +$logger2->logFlush(); //try delete the created shipper /* From faa03414a508beb9de48326e67ed326a4e23e9b4 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Fri, 2 Feb 2018 22:46:56 +0800 Subject: [PATCH 15/19] updated --- sample/demo.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sample/demo.php b/sample/demo.php index 4f0c118..0bd9cf7 100644 --- a/sample/demo.php +++ b/sample/demo.php @@ -70,10 +70,10 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { } // please update the configuration according your profile -$endpoint = 'http://cn-shanghai-corp.sls.aliyuncs.com'; -$accessKeyId = 'LTAIUbY1Pk7Ryf1P'; -$accessKey = '0oXZLJrFoRnlzVpDpopNVstd87bUWn'; -$project = 'ali-sls-sdk-test'; +$endpoint = ''; +$accessKeyId = ''; +$accessKey = ''; +$project = ''; $logstore = 'test'; $token = ""; From 4215f3fb1c6f0ad9e25f67baa5fdb30acfed1c4d Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Fri, 2 Feb 2018 22:51:23 +0800 Subject: [PATCH 16/19] updated --- Aliyun/Log/LoggerFactory.php | 9 +- Aliyun/Log/SimpleLogger.php | 165 ++++++++++++++++------------------- 2 files changed, 80 insertions(+), 94 deletions(-) diff --git a/Aliyun/Log/LoggerFactory.php b/Aliyun/Log/LoggerFactory.php index 79e9121..7486973 100644 --- a/Aliyun/Log/LoggerFactory.php +++ b/Aliyun/Log/LoggerFactory.php @@ -18,11 +18,12 @@ public static function getLogger($client, $project, $logstore, $topic = null){ if($logstore === null || $logstore == ''){ throw new Exception('logstore name is blank!'); } - if($topic === null || $topic === ''){ - $topic = 'MainFlow'; + if($topic === null){ + $topic = ''; } $loggerKey = $project.'#'.$logstore.'#'.$topic; - if (!array_key_exists($loggerKey, static::$loggerMap) || static::$loggerMap[$loggerKey] === null) { + if (!array_key_exists($loggerKey, static::$loggerMap)) + { $instanceSimpleLogger = new Aliyun_Log_SimpleLogger($client,$project,$logstore,$topic); static::$loggerMap[$loggerKey] = $instanceSimpleLogger; } @@ -44,4 +45,4 @@ function __destruct() { } } } -} \ No newline at end of file +} diff --git a/Aliyun/Log/SimpleLogger.php b/Aliyun/Log/SimpleLogger.php index db2fad2..75142f4 100644 --- a/Aliyun/Log/SimpleLogger.php +++ b/Aliyun/Log/SimpleLogger.php @@ -12,14 +12,18 @@ class Aliyun_Log_SimpleLogger{ private $logItems = []; - private $arraySize; + private $maxCacheLog; private $topic; - private $waitTime; + private $maxWaitTime; private $previousLogTime; + private $maxCacheBytes; + + private $cacheBytes; + private $client; private $project; @@ -32,21 +36,27 @@ class Aliyun_Log_SimpleLogger{ * @param $project the corresponding project * @param $logstore the logstore * @param $topic - * @param null $cacheLogCount max log items limitation, by default it's 100 - * @param null $cacheLogWaitTime max thread waiting time, bydefault it's 5 seconds + * @param null $maxCacheLog max log items limitation, by default it's 100 + * @param null $maxWaitTime max thread waiting time, bydefault it's 5 seconds */ - public function __construct($client, $project, $logstore, $topic, $cacheLogCount = null, $cacheLogWaitTime = null) + public function __construct($client, $project, $logstore, $topic, $maxCacheLog = null, $maxWaitTime = null, $maxCacheBytes = null) { - if(NULL === $cacheLogCount || !is_integer($cacheLogCount)){ - $this->arraySize = 10; + if(NULL === $maxCacheLog || !is_integer($maxCacheLog)){ + $this->maxCacheLog = 100; + }else{ + $this->maxCacheLog = $maxCacheLog; + } + + if(NULL === $maxCacheBytes || !is_integer($maxCacheBytes)){ + $this->maxCacheBytes = 256 * 1024; }else{ - $this->arraySize = $cacheLogCount; + $this->maxCacheBytes = $maxCacheBytes; } - if(NULL === $cacheLogWaitTime || !is_integer($cacheLogWaitTime)){ - $this->waitTime = 5; + if(NULL === $maxWaitTime || !is_integer($maxWaitTime)){ + $this->maxWaitTime = 5; }else{ - $this->waitTime = $cacheLogWaitTime; + $this->maxWaitTime = $maxWaitTime; } if($client == null || $project == null || $logstore == null){ throw new Exception('the input parameter is invalid! create SimpleLogger failed!'); @@ -55,95 +65,58 @@ public function __construct($client, $project, $logstore, $topic, $cacheLogCount $this->project = $project; $this->logstore = $logstore; $this->topic = $topic; - } - - /** - * log expected message with proper level - * @param $logMessage - * @param $logLevel - * @param $topic should be null - */ - private function log(Aliyun_Log_Models_LogLevel_LogLevel $logLevel,$logMessage){ - $previousCallTime = $this->previousLogTime; - if(null === $previousCallTime){ - $previousCallTime = 0; - } $this->previousLogTime = time(); - if(is_array($logMessage)){ - throw new Exception('array is not supported in this function, please use logArrayMessage!'); - }else{ - $logItems = $this->logItems; - $contents = array( // key-value pair - 'time'=>date('m/d/Y h:i:s a', time()), - 'message'=> $logMessage, - 'loglevel'=> Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel) - ); - $logItem = new Aliyun_Log_Models_LogItem(); - $logItem->setTime(time()); - $logItem->setContents($contents); - - array_push($logItems, $logItem); - - if((sizeof($logItems) == $this->arraySize - || $this->previousLogTime - $previousCallTime > 5000) - && $previousCallTime > 0){ - $this->logBatch($logItems, $this->topic); - $logItems = []; - } - $this->logItems = $logItems; - } + $this->cacheBytes = 0; } - private function logItem($logItem){ - $previousCallTime = $this->previousLogTime; - if(null === $previousCallTime){ - $previousCallTime = 0; - } - $this->previousLogTime = time(); - $logItems = $this->logItems; - - array_push($logItems, $logItem); - - if((sizeof($logItems) == $this->arraySize - || $this->previousLogTime - $previousCallTime > 5000) - && $previousCallTime > 0){ - $this->logBatch($logItems, $this->topic); - $logItems = []; + private function logItem($cur_time, $logItem){ + array_push($this->logItems, $logItem); + if ($cur_time - $this->previousLogTime >= $this->maxWaitTime || sizeof($this->logItems) >= $this->maxCacheLog + || $this->cacheBytes >= $this->maxCacheBytes) + { + $this->logBatch($this->logItems, $this->topic); + $this->logItems = []; + $this->previousLogTime = time(); + $this->cacheBytes = 0; } - $this->logItems = $logItems; } - public function logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ - if(!$logLevel instanceof Aliyun_Log_Models_LogLevel_LogLevel){ - throw new Exception('LogLevel value is invalid!'); - } + private function logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ if(is_array($logMessage)){ throw new Exception('array is not supported in this function, please use logArrayMessage!'); } - $this->log($logLevel, $logMessage); + $cur_time = time(); + $contents = array( // key-value pair + 'time'=>date('m/d/Y h:i:s a', $cur_time), + 'loglevel'=> Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel), + 'msg'=>$logMessage + ); + $this->cacheBytes += strlen($logMessage) + 32; + $logItem = new Aliyun_Log_Models_LogItem(); + $logItem->setTime($cur_time); + $logItem->setContents($contents); + $this->logItem($cur_time, $logItem); } - public function logArrayMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ - if(!$logLevel instanceof Aliyun_Log_Models_LogLevel_LogLevel){ - throw new Exception('LogLevel value is invalid!'); - } + private function logArrayMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ if(!is_array($logMessage)){ throw new Exception('input message is not array, please use logSingleMessage!'); } + $cur_time = time(); $contents = array( // key-value pair - 'time'=>date('m/d/Y h:i:s a', time()) + 'time'=>date('m/d/Y h:i:s a', $cur_time) ); - $ip = $this->getLocalIp(); - if(is_array($logMessage)){ - foreach ($logMessage as $key => $value) - $contents[$key] = $value; - } $contents['logLevel'] = Aliyun_Log_Models_LogLevel_LogLevel::getLevelStr($logLevel); + foreach ($logMessage as $key => $value) + { + $contents[$key] = $value; + $this->cacheBytes += strlen($key) + strlen($value); + } + $this->cacheBytes += 32; $logItem = new Aliyun_Log_Models_LogItem(); - $logItem->setTime(time()); + $logItem->setTime($cur_time); $logItem->setContents($contents); - - $this->logItem($logItem); + $this->logItem($cur_time, $logItem); } public function info( $logMessage){ @@ -190,14 +163,24 @@ private function getLocalIp(){ private function logBatch($logItems, $topic){ $ip = $this->getLocalIp(); - try{ - $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, - $topic, $ip, $logItems); - $response = $this->client->putLogs($request); - } catch (Aliyun_Log_Exception $ex) { - var_dump($ex); - } catch (Exception $ex) { - var_dump($ex); + $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, + $topic, $ip, $logItems); + $error_exception = NULL; + for($i = 0 ; $i < 3 ; $i++) + { + try{ + $response = $this->client->putLogs($request); + return; + } catch (Aliyun_Log_Exception $ex) { + $error_exception = $ex; + } catch (Exception $ex) { + var_dump($ex); + $error_exception = $ex; + } + } + if ($error_exception != NULL) + { + var_dump($error_exception); } } @@ -208,6 +191,8 @@ public function logFlush(){ if(sizeof($this->logItems) > 0){ $this->logBatch($this->logItems, $this->topic); $this->logItems = []; + $this->previousLogTime= time(); + $this->cacheBytes = 0; } } @@ -216,4 +201,4 @@ function __destruct() { $this->logBatch($this->logItems, $this->topic); } } -} \ No newline at end of file +} From 9232ddb888417dbdb8aafbb486618e2b35b99437 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Sun, 4 Feb 2018 14:48:06 +0800 Subject: [PATCH 17/19] comment and description added --- Aliyun/Log/LoggerFactory.php | 21 +++++ Aliyun/Log/SimpleLogger.php | 107 +++++++++++++++++++++++++- sample/{demo.php => loggerSample.php} | 35 ++++++++- 3 files changed, 161 insertions(+), 2 deletions(-) rename sample/{demo.php => loggerSample.php} (91%) diff --git a/Aliyun/Log/LoggerFactory.php b/Aliyun/Log/LoggerFactory.php index 7486973..4a918de 100644 --- a/Aliyun/Log/LoggerFactory.php +++ b/Aliyun/Log/LoggerFactory.php @@ -6,11 +6,22 @@ /** * Class Aliyun_Log_LoggerFactory + * Factory for creating logger instance, with $client, $project, $logstore, $topic configurable. + * Will flush current logger when the factory instance was recycled. */ class Aliyun_Log_LoggerFactory{ private static $loggerMap = array(); + /** + * Get logger instance + * @param $client valid log client + * @param $project which could be created in AliYun Logger Server configuration page + * @param $logstore which could be created in AliYun Logger Server configuration page + * @param null $topic used to specified the log by TOPIC field + * @return mixed return logger instance + * @throws Exception if the input parameter is invalid, throw exception + */ public static function getLogger($client, $project, $logstore, $topic = null){ if($project === null || $project == ''){ throw new Exception('project name is blank!'); @@ -30,14 +41,24 @@ public static function getLogger($client, $project, $logstore, $topic = null){ return static::$loggerMap[$loggerKey]; } + /** + * set modifier to protected for singleton pattern + * Aliyun_Log_LoggerFactory constructor. + */ protected function __construct() { } + /** + * set clone function to private for singleton pattern + */ private function __clone() {} + /** + * flush current logger in destruct function + */ function __destruct() { if(static::$loggerMap != null){ foreach (static::$loggerMap as $innerLogger){ diff --git a/Aliyun/Log/SimpleLogger.php b/Aliyun/Log/SimpleLogger.php index 75142f4..8885544 100644 --- a/Aliyun/Log/SimpleLogger.php +++ b/Aliyun/Log/SimpleLogger.php @@ -6,28 +6,69 @@ /** * Class Aliyun_Log_SimpleLogger - * simple logger for submit log message + * a wrapper for submit log message to server, to avoid post log frequently, using a internal cache for messages + * When the count of messages reach the cache size, SimpleLogger will post the messages in bulk, and reset the cache accordingly. */ class Aliyun_Log_SimpleLogger{ + /** + * internal cache for log messages + * @var array + */ private $logItems = []; + /** + * max size of cached messages + * @var int + */ private $maxCacheLog; + /** + * log topic field + * @var + */ private $topic; + /** + * max time before logger post the cached messages + * @var int + */ private $maxWaitTime; + /** + * previous time for posting log messages + * @var int + */ private $previousLogTime; + /** + * max storage size for cached messages + * @var int + */ private $maxCacheBytes; + /** + * messages storage size for cached messages + * @var int + */ private $cacheBytes; + /** + * log client which was wrappered by this logger + * @var log + */ private $client; + /** + * log project name + * @var the + */ private $project; + /** + * logstore name + * @var the + */ private $logstore; /** @@ -69,6 +110,11 @@ public function __construct($client, $project, $logstore, $topic, $maxCacheLog = $this->cacheBytes = 0; } + /** + * add logItem to cached array, and post the cached messages when cache reach the limitation + * @param $cur_time + * @param $logItem + */ private function logItem($cur_time, $logItem){ array_push($this->logItems, $logItem); if ($cur_time - $this->previousLogTime >= $this->maxWaitTime || sizeof($this->logItems) >= $this->maxCacheLog @@ -81,6 +127,12 @@ private function logItem($cur_time, $logItem){ } } + /** + * log single string message + * @param Aliyun_Log_Models_LogLevel_LogLevel $logLevel + * @param $logMessage + * @throws Exception + */ private function logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ if(is_array($logMessage)){ throw new Exception('array is not supported in this function, please use logArrayMessage!'); @@ -98,6 +150,12 @@ private function logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $this->logItem($cur_time, $logItem); } + /** + * log array message + * @param Aliyun_Log_Models_LogLevel_LogLevel $logLevel + * @param $logMessage + * @throws Exception + */ private function logArrayMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $logMessage){ if(!is_array($logMessage)){ throw new Exception('input message is not array, please use logSingleMessage!'); @@ -119,40 +177,82 @@ private function logArrayMessage(Aliyun_Log_Models_LogLevel_LogLevel $logLevel, $this->logItem($cur_time, $logItem); } + /** + * submit string log message with info level + * @param $logMessage + */ public function info( $logMessage){ $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(); $this->logSingleMessage($logLevel, $logMessage); } + + /** + * submit string log message with debug level + * @param $logMessage + */ public function debug($logMessage){ $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelDebug(); $this->logSingleMessage($logLevel, $logMessage); } + + /** + * submit string log message with warn level + * @param $logMessage + */ public function warn($logMessage){ $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelWarn(); $this->logSingleMessage($logLevel, $logMessage); } + + /** + * submit string log message with error level + * @param $logMessage + */ public function error($logMessage){ $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelError(); $this->logSingleMessage($logLevel, $logMessage); } + /** + * submit array log message with info level + * @param $logMessage + */ public function infoArray($logMessage){ $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(); $this->logArrayMessage($logLevel, $logMessage); } + + /** + * submit array log message with debug level + * @param $logMessage + */ public function debugArray($logMessage){ $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelDebug(); $this->logArrayMessage($logLevel, $logMessage); } + + /** + * submit array log message with warn level + * @param $logMessage + */ public function warnArray($logMessage){ $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelWarn(); $this->logArrayMessage($logLevel, $logMessage); } + + /** + * submit array log message with error level + * @param $logMessage + */ public function errorArray( $logMessage){ $logLevel = Aliyun_Log_Models_LogLevel_LogLevel::getLevelError(); $this->logArrayMessage($logLevel, $logMessage); } + /** + * get current machine IP + * @return string + */ private function getLocalIp(){ $local_ip = getHostByName(php_uname('n')); if(strlen($local_ip) == 0){ @@ -161,6 +261,11 @@ private function getLocalIp(){ return $local_ip; } + /** + * submit log messages in bulk + * @param $logItems + * @param $topic + */ private function logBatch($logItems, $topic){ $ip = $this->getLocalIp(); $request = new Aliyun_Log_Models_PutLogsRequest($this->project, $this->logstore, diff --git a/sample/demo.php b/sample/loggerSample.php similarity index 91% rename from sample/demo.php rename to sample/loggerSample.php index 0bd9cf7..d1a7842 100644 --- a/sample/demo.php +++ b/sample/loggerSample.php @@ -6,6 +6,12 @@ require_once realpath(dirname(__FILE__) . '/../Log_Autoload.php'); +/** + * List all shards in current log configuration + * @param Aliyun_Log_Client $client + * @param $project + * @param $logstore + */ function listShard(Aliyun_Log_Client $client,$project,$logstore){ $request = new Aliyun_Log_Models_ListShardsRequest($project,$logstore); try @@ -21,6 +27,12 @@ function listShard(Aliyun_Log_Client $client,$project,$logstore){ } } +/** + * sumit log by client directly + * @param Aliyun_Log_Client $client + * @param $project + * @param $logstore + */ function putLogs(Aliyun_Log_Client $client, $project, $logstore) { $topic = 'TestTopic'; @@ -45,6 +57,12 @@ function putLogs(Aliyun_Log_Client $client, $project, $logstore) { } } +/** + * query log by client directly + * @param Aliyun_Log_Client $client + * @param $project + * @param $logstore + */ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $topic = 'MainFlow'; $from = time()-3600; @@ -77,29 +95,44 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $logstore = 'test'; $token = ""; + + // create a log client $client = new Aliyun_Log_Client($endpoint, $accessKeyId, $accessKey,$token); listShard($client,$project,$logstore); +// create a logger instance by calling factory method $logger = Aliyun_Log_LoggerFactory::getLogger($client, $project, $logstore); $logMap = array( 'message' => 'tet', 'haha' => 'hehe' ); +// submit single string message by logger $logger->logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG'); +//create same logger instance by calling factory method with same parameters $logger2 = Aliyun_Log_LoggerFactory::getLogger($client, $project, $logstore); + + $logger2->logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'test INFO LOG2222222', 'MainFlow'); +// submit single array message by logger $logger->logArrayMessage(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),$logMap, 'MainFlow'); //$logger->log('test', 'something wrong with the inner info', 'MainFlow'); + +//create different logger instance by calling factory method with topic parameter defined $batchLogger = Aliyun_Log_LoggerFactory::getLogger($client, $project, $logstore,'helloworld'); -for($i = 1; $i <= 29; $i++){ +// batch submit single string message, with default cache size 100 +for($i = 1; $i <= 129; $i++){ $batchLogger->logSingleMessage(Aliyun_Log_Models_LogLevel_LogLevel::getLevelInfo(),'something wrong with the inner info '.$i); } + +// manually flush log message $batchLogger->logFlush(); + + getLogs($client,$project,$logstore); $logger2->info('test log message 000 info'); From 27208abdf60c864f43fd2c6d97787c1aeea68480 Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Sun, 4 Feb 2018 14:49:23 +0800 Subject: [PATCH 18/19] comment and description added --- sample/loggerSample.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sample/loggerSample.php b/sample/loggerSample.php index d1a7842..024ff0a 100644 --- a/sample/loggerSample.php +++ b/sample/loggerSample.php @@ -151,8 +151,7 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $logger2->logFlush(); -//try delete the created shipper -/* +//try delete the existing shipper $deleteShipper = new Aliyun_Log_Models_DeleteShipperRequest($project); $deleteShipper->setShipperName('testjsonshipper'); $deleteShipper->setLogStore($logstore); @@ -299,4 +298,4 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $retryShipperTask->setLogStore($logstore); $retryShipperTask->setTaskLists($taskIdList); $client->retryShipperTasks($retryShipperTask); -*/ + From c950d8066a973457b80441a0f63d912b63d8f4ba Mon Sep 17 00:00:00 2001 From: "qiaobo.qb" Date: Sun, 4 Feb 2018 14:51:32 +0800 Subject: [PATCH 19/19] comment and description added --- sample/loggerSample.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sample/loggerSample.php b/sample/loggerSample.php index 024ff0a..cc1bd56 100644 --- a/sample/loggerSample.php +++ b/sample/loggerSample.php @@ -178,16 +178,17 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $ossCsvStorage->setNullIdentifier(''); $ossCsvStorage->setFormat('csv'); +// create a json shipper $ossJsonStorage = new Aliyun_Log_Models_OssShipperJsonStorage(); $ossJsonStorage->setFormat('json'); $ossConfig = new Aliyun_Log_Models_OssShipperConfig(); -$ossConfig->setOssBucket('sls-test-oss-shipper'); -$ossConfig->setOssPrefix('logtailalarm'); +$ossConfig->setOssBucket('');// please change it according your own profile +$ossConfig->setOssPrefix('');// please change it according your own profile $ossConfig->setBufferInterval(300); $ossConfig->setBufferSize(5); $ossConfig->setCompressType('none'); -$ossConfig->setRoleArn('acs:ram::1654218965343050:role/aliyunlogdefaultrole'); +$ossConfig->setRoleArn('');// please change it according your own profile $ossConfig->setStorage($ossCsvStorage); $ossConfig->setPathFormat('%Y/%m/%d/%H'); @@ -229,7 +230,7 @@ function getLogs(Aliyun_Log_Client $client, $project, $logstore) { $ossConfig->setStorage($ossJsonStorage); $shipper->setTargetConfigration($ossConfig->to_json_object()); try{ - //$client->createShipper($shipper); + $client->createShipper($shipper); }catch (Exception $exception){ var_dump($exception); }