razonyang / yii-log

Enhanced DB Target for Yii2 Log Component

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enhanced DB Target for Yii2 Log Component

Packagist Packagist Travis

I wrote this extension for resolving the following problems:

  1. The logs are chaotic, I cannot distinguish which logs are came from the same requests. It is hard to debug in concurrent scenarios.
  2. The yii\log\DbTarget does not provide GC feature.

Installation

composer require --prefer-dist razonyang/yii-log

Usage

The usage is similar to yii\log\DbTarget.

Configuration

[

    'components' => [

        'log' => [
            'targets' => [
                [
                    'class' => \razonyang\yii\log\DbTarget::class,
                    'levels' => ['error', 'warning'],
                    'logTable' => '{{%log}}',
                    'logMessageTable' => '{{%log_message}}',

                    // garbage collection
                    'maxLifeTime' => 30*24*3600, // 30 days
                ],
            ],
        ],

    ],


    // migrate and garbage collection settings for console application.
    'controllerMap' => [
        'migrate' => [
            'class' => \yii\console\controllers\MigrateController::class,
            'migrationPath' => [

                '@vendor/razonyang/yii-log/src/migrations',

            ],
        ],
        'log' => [
            'class' => \razonyang\yii\log\LogController::class,
        ]
    ],

]

Migrate

./yii migrate

Garbage Collection

./yii log/gc

About

Enhanced DB Target for Yii2 Log Component


Languages

Language:PHP 100.0%