PHP code example of unrelaxs / eslog-for-laravel

1. Go to this page and download the library: Download unrelaxs/eslog-for-laravel 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/ */

    

unrelaxs / eslog-for-laravel example snippets


'providers' => [
    Laravel\Scout\ScoutServiceProvider::class,
    ScoutElastic\ScoutElasticServiceProvider::class,
    Unrelaxs\eslog\EslogServiceProvider::class,
]

php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
php artisan vendor:publish --provider="ScoutElastic\ScoutElasticServiceProvider"
php artisan vendor:publish --provider="Unrelaxs\eslog\EslogServiceProvider"

    'channels' => [
        'stack' => [
            'driver' => 'stack',
            'channels' => ['custom'],  //这里至少指定 custom
            'ignore_exceptions' => false,
        ],
        'custom'  => [
            'driver' => 'custom',
            'via' => Unrelaxs\Eslog\Log\Handler\CreateEsLogger::class, //指定创建es的logger扩展包
            'url' =>  'http://ip', es的链接
            'port'=> '9200',
            'index'=> 'laralog', //es的索引名
            'toDB' => false, //是否写入数据库
        ]

php artisan make:index-configurator \\App\\Elasticsearch\\LogIndexConfigurator

php artisan unrelaxs:create-mapping "\App\Elasticsearch\LogIndexConfigurator"

php artisan elastic:create-index "\App\Elasticsearch\LogIndexConfigurator"

php artisan elastic:update-mapping "\Unrelaxs\Eslog\Model\LogModel"

Route::get('/', function () {
    \Illuminate\Support\Facades\Log::info('成功加载');  //记录日志,将自动把数据推送到es服务器
    return view('welcome');
});