PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 27, 2022

[FIXED] Yii separate log files for each user

 January 27, 2022     logging, yii     No comments   

Issue

I want to store my log messages in separate log files for each user. My current config is like:

'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
    array(
        'class'=>'CFileLogRoute',
        'logFile'=>'custom.log.u1',
        'categories'=>'error.*',
    ),
    array(
        'class'=>'CFileLogRoute',
        'logFile'=>'custom.log.u2',
        'categories'=>'error.*',
    ),
    ...
))

but my user are more than 2 and the log file name should set dynamically ... how can i do that ... ?


Solution

The I can think of is to extend CFileLogRoute and override some of the functions:

make a php file named MyLog in a folder that gets autoloaded like components

class MyLog extends CFileLogRoute
{
    public $filderName;

    public function getLogFile()
    {
        return parent::getLogFile() . (int)Yii::app()->user->id;
    }

    public function setLogFile($value)
    {
        parent::setLogFile($value . (int)Yii::app()->user->id);
    }
}

then in your config:

'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
    array(
        'class'=>'MyLog',
        'categories'=>'error.*',
    ),
    ...
))


Answered By - Developerium
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing