PHP code example of cebe / yii2-loki-log-target

1. Go to this page and download the library: Download cebe/yii2-loki-log-target 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/ */

    

cebe / yii2-loki-log-target example snippets


// ...
'components' => [
    // ...
    'log' => [
        // ...
        'targets' => [
            [
                'class' => \cebe\lokilogtarget\LokiLogTarget::class,
                //'enabled' => YII_ENV_PROD,

                'lokiPushUrl' => 'https://loki.example.com/loki/api/v1/push',
                'lokiAuthUser' => 'loki', // HTTP Basic Auth User
                'lokiAuthPassword' => '...', // HTTP Basic Auth Password

                'levels' => ['error', 'warning', 'info'],

                // optionally exclude categories
                'except' => [
                    'yii\db\Connection::open',
                    'yii\db\Command::execute',
                    'yii\httpclient\StreamTransport::send',
                ],

                // optionally re-map log level for certain categories
                'levelMap' => [
                    // yii category
                    'yii\web\HttpException:404' => [
                        // yii level => loki level
                        // set loki level to false, to drop messages with that category
                        '*' => 'info',
                    ],
                    'yii\web\HttpException:401' => [
                        // yii level => loki level
                        // set loki level to false, to drop messages with that category
                        '*' => 'warning',
                    ],
                ],

            ],
        ],
    ],
]