samdark/yii2-psr-log-target Yii 2 log target which uses PSR-3 compatible logger

Yii 2 PSR Log Target

  1. Installation
  2. Usage
  3. Running tests

Allows you to process logs using any PSR-3 compatible logger such as Monolog.

<img src="https://travis-ci.org/samdark/yii2-psr-log-target.svg" />

Installation

composer require "samdark/yii2-psr-log-target"

Usage

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

// $psrLogger should be an instance of PSR-3 compatible logger.
// As an example, we'll use Monolog to send log to Slack.
$psrLogger = new \Monolog\Logger('my_logger');
$psrLogger->pushHandler(new \Monolog\Handler\SlackHandler('slack_token', 'logs', null, true, null, \Monolog\Logger::DEBUG));

return [
    // ...
    'bootstrap' => ['log'],    
    // ...    
    'components' => [
        // ...        
        'log' => [
            'targets' => [
                [
                    'class' => 'samdark\log\PsrTarget',
                    'logger' => $psrLogger,
                    
                    // It is optional parameter. The message levels that this target is interested in.
                    // The parameter can be an array.
                    'levels' => ['info', yii\log\Logger::LEVEL_WARNING, Psr\Log\LogLevel::CRITICAL],
                ],
                // ...
            ],
        ],
    ],
];

Standard usage:

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

Usage with PSR logger levels:

Yii::getLogger()->log('Critical message', Psr\Log\LogLevel::CRITICAL);
Yii::getLogger()->log('Alert message', Psr\Log\LogLevel::ALERT);

Running tests

In order to run tests perform the following commands:

composer install
./vendor/bin/phpunit
0 0
2 followers
12 311 downloads
Yii Version: 2.0
License: BSD-3-Clause
Category: Logging
Tags: PSR-3
Developed by: samdark
Created on: Mar 23, 2018
Last updated: (not set)
Packagist Profile
Github Repository