PHP code example of we-push-it / yii2-splunk-log-target

1. Go to this page and download the library: Download we-push-it/yii2-splunk-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/ */

    

we-push-it / yii2-splunk-log-target example snippets


return [
    // ...
    'bootstrap' => ['log'],    
    // ...    
    'components' => [
        // ...        
        'log' => [
            'targets' => [
                [
                    'class' => wepushit\log\SplunkTarget::class,
                    
                    // It is optional parameter. The message levels that this target is interested in.
                    // The parameter can be an array.
                    'levels' => ['error', 'warning'],
                ],
                // ...
            ],
        ],
    ],
];

'log' => [
    'traceLevel' => YII_DEBUG ? 3 : 0,
    'targets' => [
        [
            'class' => yii\log\FileTarget::class,
            'levels' => ['error', 'warning'],
        ],
        [
            'class' => wepushit\log\SplunkTarget::class,
            'levels' => ['error', 'warning']
        ],
    ],
],

return [
    // ...
    'splunk' => [
        'host' => isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'example server',
        'token' => 'token from your Splunk HTTP Event Collector',
        'url' => 'https://example.com:8088/services/collector/event',
        'source' => 'example',
        'sourcetype' => 'yii-errorhandler',
    ],
];

Yii::info('Info message');
Yii::error('Error message');