PHP code example of zatxm / yii2-monolog

1. Go to this page and download the library: Download zatxm/yii2-monolog 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/ */

    

zatxm / yii2-monolog example snippets


use Monolog\Handler\StreamHandler;
use Monolog\Logger;

$logger = new Logger('my_logger');
$logger->pushHandler(new StreamHandler(__DIR__.'/my_app.log', Logger::Debug));

return [
    // ...
    'bootstrap' => ['log'],    
    // ...    
    'components' => [
        // ...        
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => \Zatxm\YiiMonolog\MonologTarget::class,
                    'extractTrace' => false, //记录堆栈,可以不配置,默认false
                    'logger' => '', //要用原生的monolog一定保留此键,空字符系统会生成monolog logger
                    // 'logger' => $logger, //或者用这个自己定义的monolog logger
                    // 'logger' => function () {
                    //     $logger = new Logger('my_logger');
                    //     $logger->pushHandler(new StreamHandler(__DIR__.'/my_app.log', Logger::Debug));
                    //     return $logger;
                    // } // 或者用闭包
                    'levels' => ['error', 'warning']
                ]
            ],
        ]
    ],
];

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

Yii::$app->monolog->info('My logger is now ready');