PHP code example of aston / aliyun-sls

1. Go to this page and download the library: Download aston/aliyun-sls library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aston / aliyun-sls example snippets


return [
    'write_switch' => (bool)env('WRITE_SLS', true),//写日志开关
    //默认日志配置组
    'default' => [
        'endpoint' => env('ALIYUN_SLS_ENDPOINT'),
        'access_key' => env('ALIYUN_SLS_AK'),
        'secret_key' => env('ALIYUN_SLS_SK'),
        'project' => env('ALIYUN_SLS_PROJECT'),
        'logstore' => env('ALIYUN_SLS_LOGSTORE'),
    ],
    //自定义日志配置组 可选
    'another' => [
        'endpoint' => env('ANOTHER_ALIYUN_SLS_ENDPOINT'),
        'access_key' => env('ANOTHER_ALIYUN_SLS_AK'),
        'secret_key' => env('ANOTHER_ALIYUN_SLS_SK'),
        'project' => env('ANOTHER_ALIYUN_SLS_PROJECT'),
        'logstore' => env('ANOTHER_ALIYUN_SLS_LOGSTORE'),
    ]
];


use Aston\AliyunSls\Logger;

//通过默认日志配置 写入
Logger::instance()->write('testLog', [
    'is_test' => 1
]);
//等价于
Logger::instance('default')->write('testLog', [
    'is_test' => 1
]);


//通过指定日志配置 读取
$log = Logger::instance('another')->read(
   $start_timestamp,
   $end_timestamp,
   $topic,
   '* |SELECT "message.customer_user_id" limit 1'
);


php bin/hyperf.php vendor:publish aston/aliyun-sls