Advanced Logging in Yii

Here are some nice examples of using the logging facilities in Yii


 'log'=>array(
      'class'=>'CLogRouter',
      'routes'=>array(
                            array(
                                'class'=>'CWebLogRoute',
                                    // you can include more levels separated by commas
                                'levels'=>'trace, info, error, warning, vardump',
                                    // categories are those you used in the call to Yii::trace
                                'categories'=>'*',
                                // This is self-explanatory right? but also works in Chrome!
                                'showInFireBug'=>true
                            ),
                            array(
                                'class'=>'CFileLogRoute',
                                'levels'=>'trace, info, error, warning, vardump',
                            ),
                          /*  array(
                                'class'=>'CEmailLogRoute',
                                'levels'=>'error, warning',
                                'emails'=>'me@example.com',
                            ),*/
      ),
    ),

I use a function to create a trace log, defined in my base index.php as follows:-


function fb($what,$where='fb.somewhere'){
    $what=print_r($what,true);
     Yii::trace(CVarDumper::dumpAsString($what,10),$where);
     if ($where=='trace')
         Yii::log($what, 'info', 'application');
}

In this way, I just need to add "fb ($variable, "optional category or comment");" in my code!


Did you know you can hire me?

I take on projects of all sizes. From Consulting to large Development Projects.

If you're starting a new Yii project and would like some help to get setup and running or you need some help with a particular module or you just need someone to develop the whole dang thing, then just ask ...


Jumpstart Yii2 ... Coming Soon!

I'm in the process of planning a new course on Yii2 and want your feedback.

What is your preferred format? What did you think of my Yii 1.x video course "Beginning Yii"?

What would you like to see different?

How much would you pay?

Leave a Comment

twitterfacebookgooglelinkedin https://me.yahoo.com