pandasir / laravel-sls

Aliyun SLS Log For Laravel

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Aliyun SLS Log For Laravel

说明

此包来源于 lokielse/laravel-sls

Latest Version on Packagist Software License Total Downloads

Install

Via Composer

$ composer require pandasir/laravel-sls

Config

If you’re on Laravel 5.5 or later the package will be auto-discovered. Otherwise you will need to manually configure it in your config/app.php.

Add following service providers into your providers array in config/app.php

'providers' => array(
    // ...
    Lokielse\LaravelSLS\LaravelSLSServiceProvider::class,
),
'aliases' => array(
    // ...
    'SLSLog' => Lokielse\LaravelSLS\Facades\SlSLog::class,
),

If you’re need Log you can replace Log alias in your config/app.php

//'Log'               => Illuminate\Support\Facades\Log::class,
'Log'                 => Lokielse\LaravelSLS\Facades\SLSLogWriter::class,

Publish sls.php to config folder

php artisan vendor:publish --provider="Lokielse\LaravelSLS\LaravelSLSServiceProvider" 

Edit your .env file

ALIYUN_ACCESS_KEY_ID=...
ALIYUN_ACCESS_KEY_SECRET=...
# https://help.aliyun.com/document_detail/29008.html
# 如杭州公网 cn-hangzhou.log.aliyuncs.com
# 如杭州内网 cn-hangzhou-intranet.log.aliyuncs.com
SLS_ENDPOINT=cn-hangzhou.log.aliyuncs.com
SLS_PROJECT=test-project
SLS_STORE=test-store

You should update SLS_ENDPOINT to internal endpoint in production mode

Usage

First create a project and store at Aliyun SLS Console

Then update SLS_ENDPOINT, SLS_PROJECT, SLS_STORE in .env

Push a test message to queue

Log::info('Test Message', ['foobar'=>'2003']);

//or you can use `app('sls')` 

app('sls')->putLogs([
	'type' => 'test',
	'message' => json_encode(['This should use json_encode'])
]);

//or you can use `SLSLog` directly 

SLSLog::putLogs([
	'type' => 'test',
	'message' => json_encode(['This should use json_encode'])
]);

Security

Create RAM access control at Aliyun RAM Console

  1. Create a custom policy such as AliyunSLSFullAccessFoobar

    {
      "Version": "1",
      "Statement": [
    	{
    	  "Action": "log:*",
    	  "Resource": [
    		"acs:log:*:*:project/test-project/logstore/test-store",
    	  ],
    	  "Effect": "Allow"
    	}
      ]
    }
    
  2. Create a user for you app such as foobar

  3. Assign the policy AliyunSLSFullAccessFoobar to the user foobar

  4. Create and get the AccessKeyId and AccessKeySecret for user foorbar

  5. update QUEUE_SLS_ACCESS_KEY and QUEUE_SLS_ACCESS_SECRET in .env

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Credits

License

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

About

Aliyun SLS Log For Laravel

License:MIT License


Languages

Language:PHP 100.0%