Skip to content

chathurasudarsha/LogTargetFile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Yii2 LogTargetFile

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,

        '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

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

About

Yii2 Log file

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages