PHP code example of mitrm / yii2-logstash

1. Go to this page and download the library: Download mitrm/yii2-logstash 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/ */

    

mitrm / yii2-logstash example snippets


        'logstash' => [
            'class' => \mitrm\logstash\LogstashSend::class,
            'config' => [
                'class' => \mitrm\logstash\transport\TcpTransport::class,
                'socket' => 'tcp://localhost:5000'
            ],
        ],

        'logstash' => [
            'class' => \mitrm\logstash\LogstashSend::class,
            'config' => [
                'class' => \mitrm\logstash\transport\HttpTransport::class,
                'port' => 5001,
                'host' => 'http://localhost'
            ],
        ],

Yii::$app->logstash->sendLog(['event' => 'orderPay', 'userId' => Yii::$app->user->id]);


        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => \mitrm\logstash\LogstashTarget::class,
                    'levels' => ['error', 'warning'],
                    'logVars' => ['_GET', '_POST', '_SESSION', '_SERVER'],
                    'clientOptions' => [
                        'release' => $params['release_app'] ?? null,
                    ],
                    'isLogUser' => true, // Добавить в лог ID пользователя
                    'isLogContext' => false, 
                    'extraCallback' => function ($message, $extra) {
                        $extra['app_id'] = Yii::$app->id;
                        return $extra;
                    },
                    'except' => ['order'],
                ],
            ],
        ],


php composer.phar