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

Yii 2 log target which can log to Splunk Enterprise via curl

1.0.1 2019-12-29 10:13 UTC

This package is auto-updated.

Last update: 2024-06-30 00:58:41 UTC


README

yii2-splunk-log-target

Allows you to to send logs to your Splunk Enterprise.

Installation

composer require "we-push-it/yii2-splunk-log-target"

Usage

In order to use SplunkTarget you should configure your log application component like the following:

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'],
                ],
                // ...
            ],
        ],
    ],
];

you can also combine your log targets:

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

additionally you should adjust your params-config:

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',
    ],
];

Standard usage:

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