PHP code example of goletter / hyperf-sls-log

1. Go to this page and download the library: Download goletter/hyperf-sls-log 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/ */

    

goletter / hyperf-sls-log example snippets


use Goletter\AliYun\Sls\Handler\SlsHandler;
use Monolog\Level;

return [
    'default' => [
        'handler' => [
            'class' => SlsHandler::class,
            'constructor' => [
                'level' => Level::Info,
            ],
        ],
    ],
];

$logger->info('支付成功', ['order_id' => 1, 'user_id' => 42, 'request_id' => $rid]);

use Goletter\AliYun\Sls\Contract\LogWriterInterface;
use Goletter\AliYun\Sls\Sls;

public function __construct(private LogWriterInterface $sls) {}

$this->sls->info('业务日志', ['foo' => 'bar']);
$this->sls->flush(); // 请求结束前可主动刷缓冲

Sls::error('失败', ['reason' => 'timeout']);

use Goletter\AliYun\Sls\Contract\SlsClientInterface;
use Goletter\AliYun\Sls\Model\LogEntry;

$client->putLogs([
    LogEntry::make(['message' => 'hello', 'level' => 'INFO']),
]);

$result = $client->getLogs(time() - 3600, time(), 'level: ERROR', line: 50);
foreach ($result->logs as $row) {
    // ...
}