agielks/yii2-log-json

Convert your yii2 application logs as json and save it to file, redis, or logstash

Installs: 7 299

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.0 2022-07-05 08:31 UTC

This package is auto-updated.

Last update: 2024-10-27 14:18:10 UTC


README

Convert your yii2 application logs as json and save it to file, redis, or logstash

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist agielks/yii2-log-json "~1.0"

or add

"agielks/yii2-log-json": "~1.0"

to the require section of your composer.json file.

Basic usage

File Target

'components' => [
    // ...
    'log' => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
            [
                'class' => 'agielks\yii2\log\json\FileTarget',
                'levels' => ['error', 'warning'],
                'except' => [
                    'yii\web\HttpException:*',
                ],
            ],
        ],
    ],
    // ...
],

Logstash Target Configuration

'components' => [
    // ...
    'log' => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
            [
                'class' => 'agielks\yii2\log\json\LogstashTarget',
                'dsn' => '127.0.0.1:5000',
                'index' => 'my-index',
                'type' => 'log',
                'levels' => ['error', 'warning'],
                'except' => [
                    'yii\web\HttpException:*',
                ],
            ],
        ],
    ],
    // ...
],

Redis Target Configuration

'components' => [
    // ...

    // Redis connection
    'redis' => [
        'class' => 'yii\redis\Connection',
        'hostname' => '127.0.0.1',
        'port' => 6379,
        'database' => 0,
    ],

    // Redis log configuration
    'log' => [
        'traceLevel' => YII_DEBUG ? 3 : 0,
        'targets' => [
            [
                'class' => 'agielks\yii2\log\json\RedisTarget',
                'db' => 'redis',
                'levels' => ['error', 'warning'],
                'except' => [
                    'yii\web\HttpException:*',
                ],
            ],
        ],
    ],
    // ...
],

More Usage