Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YII logging for debugging

Tags:

php

cakephp

yii

In many cases, Xdebug is not suitable for debugging as it involves clicks to run to a particular line of codes. I want to use something that is similar to cakePHP debug function for developers to output the value of a particular property of a class to the browser.

I am using Yii framework and this is my configuration for the yii log in the main.php:

'log'=>array(
    'class'=>'CLogRouter',
        'routes'=>array(
        array(
            'class'=>'CFileLogRoute',
            'levels'=>'trace, info, error, warning, vardump',
        ),
        array(
            'class'=>'CWebLogRoute',
                                'enabled' => YII_DEBUG,
            'levels'=>'error, warning, trace, log, vardump',
            'showInFireBug'=>true,
        ),
    ),
), 

In one of my defined controller i put this code to test:

Yii::log("CallFromUserController",'info', 'application');

However i don't see this being printed in the firebug. I used Chris's example:

http://chris-backhouse.com/advanced-logging-in-yii/775

like image 211
madi Avatar asked Jul 26 '13 02:07

madi


1 Answers

I finally managed to find out a solution:

In my main.php I did this:

'log' => array(
    'class' => 'CLogRouter',
    'routes' => array(
        array(
            'class' => 'CFileLogRoute',
            'levels' => 'trace, info, error, warning, vardump',
        ),
        // uncomment the following to show log messages on web pages
        array(
            'class' => 'CWebLogRoute',
            'enabled' => YII_DEBUG,
            'levels' => 'error, warning, trace, notice',
            'categories' => 'application',
            'showInFireBug' => false,
        ),
    ),
),

In my controller I used this code:

$a = new array(1,2,3);
Yii::trace(CVarDumper::dumpAsString($a));

The Application Log is shown below in every page.

like image 56
madi Avatar answered Nov 03 '22 17:11

madi