donsimon/yii2-log-target-file Yii 2.0 customizable log message fileTarget

Yii2 LogTargetFile

  1. Installation
  2. Usage

Customize the log messages

Sort and change the log message's units

Installation

Just run in your console:

composer require donsimon/yii2-log-target-file "*"

or add

"donsimon/yii2-log-target-file": "*"

to the require section of your composer.json file.

Usage

Add following line to your main configuration file (e.g. config/main.php),

    'bootstrap' => ['log'],

Then,

Add following lines to the components section in configuration file, `php

    'log' => [
    //          'traceLevel' => YII_DEBUG ? 3 : 0,
                'targets' => [
                      [  
                            'class' => 'donsimon\log\logTargetFile',  
                            'levels' => ['info','warning','error'],
                            'categories' => ['user','application'],
                            'logVars' => ['_GET', '_POST', '_FILES', '_COOKIE', '_SESSION', '_SERVER'],
                            'logFile' => '@backend/runtime/logs/appAndUser.log',
                            'logMessageContainer' =>['timestamp','prefix','level','category','message'],
                            'prefixContainer'=>['ip','userId','sessionId']
                        ]
                ],
    ],
To write on log file client should call something like this,

 `Yii::info($message, $category);` 

Here $message and $category are variables.

your log will update.

What you can do here,
--

You can change log file name using `logFile`.

    eg: @backend/runtime/logs/user-activities.log

You can add many `categories`.

    eg: ['yii\web\HttpException:*','yii\base\ErrorException:*','user','application']

You can add many `levels` 

    eg: ['info','warning','error']

You can print vars using `logVars`.

[Refer more](https://www.yiiframework.com/doc/guide/2.0/en/runtime-logging)



New
--

`logMessageContainer` is a array of log messages units `['timestamp','prefix','level','category','message']`. 

You can sort and change log messages units using `logMessageContainer` 

`prefixContainer` is a array of prefix units `['ip','userId','sessionId']`.

You can sort and change log messages prefix using `prefixContainer`
 


2 0
2 followers
33 downloads
Yii Version: 2.0
License: BSD-3-Clause
Category: Logging
Developed by: chathura sudarsha
Created on: Nov 2, 2018
Last updated: 2 years ago
Packagist Profile
Github Repository

Related Extensions