PHP code example of kriss / yii2-redis-log

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

    

kriss / yii2-redis-log example snippets


'log' => [
    'targets' => [
        [
            'class' => 'kriss\log\RedisTarget',
            'redis' => [
                'hostname' => 'localhost',
                'port' => 6379,                        
            ],
            // If you have configured the redis yii\redis\Connection as an application component,use bwlow
            //'redis' => 'redis',
            'key' => 'yii.log',
            'levels' => ['error', 'warning'],
        ],
    ]
]

Yii::error('this is en error');

'log' => [
    'targets' => [
        [
            'class' => 'kriss\log\RedisTarget',
            'redis' => 'redis',
            'key' => 'yii.log',
            'dumpFileTarget' => [
                'logFile' => '@common/runtime/logs/error.log',
            ],
            'levels' => ['error', 'warning'],
        ],
    ]
]

$dumper = new Dump2File([
  'redisTargetKey' => 'yii.log',
]);
$dumper->dump();

$targets = Yii::$app->log->targets;
foreach ($targets as $target) {
    if ($target instanceof RedisTarget) {
        $dumper = new Dump2File([
            'redisTarget' => $target,
            'count' => 1000
        ]);
        $dumper->dump();
    }
}