Example #1
0
 /**
  * Writes log messages to a SLS.
  */
 private function _log($contents = '')
 {
     $logItem = new \Aliyun_Sls_Models_LogItem();
     $logItem->setTime(time());
     $logItem->setContents($contents);
     $logitems = [$logItem];
     $request = new \Aliyun_Sls_Models_PutLogsRequest(SLS_PROJECT_ID, SLS_LOG_STORE, SLS_LOG_TOPIC, null, $logitems);
     try {
         $res = $this->client->putLogs($request);
     } catch (\Aliyun_Sls_Exception $ex) {
         // Throw away exception
         //var_dump($ex);
     } catch (\Exception $ex) {
         //var_dump($ex);
     }
 }
Example #2
0
function putLogs(Aliyun_Sls_Client $client, $project, $logstore)
{
    $topic = 'TestTopic';
    $contents = array('TestKey' => 'TestContent');
    $logItem = new Aliyun_Sls_Models_LogItem();
    $logItem->setTime(time());
    $logItem->setContents($contents);
    $logitems = array($logItem);
    $request = new Aliyun_Sls_Models_PutLogsRequest($project, $logstore, $topic, null, $logitems);
    try {
        $response = $client->putLogs($request);
        var_dump($response);
    } catch (Aliyun_Sls_Exception $ex) {
        var_dump($ex);
    } catch (Exception $ex) {
        var_dump($ex);
    }
}