2017 © Pedro Peláez
 

yii2-extension yii2-monolog

The Monolog integration for the Yii framework.

image

mero/yii2-monolog

The Monolog integration for the Yii framework.

  • Thursday, December 29, 2016
  • by merorafael
  • Repository
  • 4 Watchers
  • 23 Stars
  • 16,068 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 13 Forks
  • 0 Open issues
  • 5 Versions
  • 11 % Grown

The README.md

Monolog for Yii 2

SensioLabsInsight Build Status Coverage Status Latest Stable Version Total Downloads License, (*1)

The Monolog integration for the Yii framework., (*2)

Requirements

  • PHP 5.4 or above
  • Yii 2.0.0 or above

Instalation with composer

  1. Open your project directory;
  2. Run composer require mero/yii2-monolog to add Monolog in your project vendor.

Configuration

To configure Monolog component in Yii2, use the structure exemplified below. The channel "main" is required in component and used when no channel is setted to use a logger., (*3)

return [
    //....
    'components' => [
        'monolog' => [
            'class' => '\Mero\Monolog\MonologComponent',
            'channels' => [
                'main' => [
                    'handler' => [
                        //Handler object or array configuration
                    ],
                    'processor' => [],
                ],
            ],
        ],
    ],
    //....
];

You can configure multiple channels and different handlers and processors for each channel., (*4)

Example, (*5)

return [
    //...
        'channels' => [
            'main' => [
                'handler' => [
                    [
                        'type' => 'stream',
                        'path' => '@app/runtime/logs/main_' . date('Y-m-d') . '.log',
                        'level' => 'debug'
                    ]
                ],
                'processor' => [],
            ],
            'channel1' => [
                'handler' => [
                    [
                        'type' => 'stream',
                        'path' => '@app/runtime/logs/channel1_' . date('Y-m-d') . '.log',
                        'level' => 'debug'
                    ]
                ],
                'processor' => [],
            ],
            'channel2' => [
                'handler' => [
                    [
                        'type' => 'stream',
                        'path' => '@app/runtime/logs/channel1_' . date('Y-m-d') . '.log',
                        'level' => 'debug'
                    ]
                ],
                'processor' => [],
            ],
        ],
    //...
];

Handlers

You can add handlers in their channels using the array structure or object structure., (*6)

Array structure

Using the array structure, you have a better readability of the configuration of their handlers., (*7)

Example, (*8)

return [
    //...
    'handler' => [
        [
            'type' => 'stream',
            'path' => '@app/runtime/logs/log_' . date('Y-m-d') . '.log',
            'level' => 'debug'
        ]
    ],
    //...
];

Warning: this option does not have any existing handlers in monolog. See the handlers page more details., (*9)

Object structure

Using the object structure, you will be informing instantiated objects already declared their respective handlers., (*10)

Example, (*11)

return [
    //...
    'handler' => [
        new \Monolog\Handler\StreamHandler(
            __DIR__.'/../runtime/logs/system.log',
            \Monolog\Logger::DEBUG
        )
    ],
    //...
];

Using Yii2 Monolog

To use Yii 2 Monolog simply call the method getLogger component informing which channel is used., (*12)

Example, (*13)

namespace app\controllers;

use Yii;
use \yii\web\Controller;

class ExampleController extends Controller
{

    /**
     * This action register "Hello world" in channel 
     * "main"(default when no value is setted on "getLogger" method).
     */
    public function actionFirstExample()
    {
        $monologComponent = Yii::$app->monolog;
        $logger = $monologComponent->getLogger();
        $logger->log('info', 'Hello world');
    }

    /**
     * This action register "Hello world" in channel "channel1".
     */
    public function actionSecondExample()
    {
        $monologComponent = Yii::$app->monolog;
        $logger = $monologComponent->getLogger("channel1");
        $logger->log('info', 'Hello world');
    }

}

The Versions

29/12 2016

dev-master

9999999-dev

The Monolog integration for the Yii framework.

  Sources   Download

MIT

The Requires

 

The Development Requires

log logging monolog yii2

12/10 2016

0.1.x-dev

0.1.9999999.9999999-dev

The Monolog integration for the Yii framework.

  Sources   Download

MIT

The Requires

 

log logging monolog yii2

12/10 2016

0.1.2

0.1.2.0

The Monolog integration for the Yii framework.

  Sources   Download

MIT

The Requires

 

log logging monolog yii2

09/10 2016

0.1.1

0.1.1.0

The Monolog integration for the Yii framework.

  Sources   Download

MIT

The Requires

 

log logging monolog yii2

03/10 2016

0.1.0

0.1.0.0

The Monolog integration for the Yii framework.

  Sources   Download

MIT

The Requires

 

log logging monolog yii2