hugmungus
hugmungus

Reputation: 896

Yii DB Profiling

I'm trying to setup the DB profiling in Yii as we're having some issues with processing large amounts of data. I'm using these instructions to set it up: Yii 1.1: Configuring CWebLogRoute for DB profiling

Here's what my code looks like

index.php

defined('YII_DEBUG') or define('YII_DEBUG',true );
//show profiler
defined('YII_DEBUG_SHOW_PROFILER') or define('YII_DEBUG_SHOW_PROFILER',true);
//enable profiling
defined('YII_DEBUG_PROFILING') or define('YII_DEBUG_PROFILING',true);
//trace level
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',0);
//execution time
defined('YII_DEBUG_DISPLAY_TIME') or define('YII_DEBUG_DISPLAY_TIME',false);

config/main.php

'db'=>array(
        'connectionString' => 'mysql:host=******;dbname=******',
        'emulatePrepare' => true,
        'username' => '******',
        'password' => '******',
        'charset' => 'utf8',
        'enableProfiling' => YII_DEBUG_PROFILING,
    ),
    'authManager'=>array(
        'class'=>'DbAuthManager',
        'connectionID'=>'db',
        'defaultRoles'=>array('guest')
    ),
    'errorHandler'=>array(
        'errorAction'=>$errorHandler,

    ),
    'log'=>array(
        'class'=>'CLogRouter',
        'routes'=>array(
            array(
                'class'=>'CFileLogRoute',
                'enabled' =>YII_DEBUG_SHOW_PROFILER,
                'levels'=>'error, warning',
            ),
        ),
    ),

After I set this all up, I got two "Undefined Constant" errors for the Constants used in the config/main.php file.

Since that wasn't working, I tried hardcoding them as TRUE, and the errors go away, but nothing happens. When I try CWebLogRoute, I don't see anything on the screen, and when I try CFileLogRoute, I don't see anything written to the Yii logs.

Any ideas as to why this isn't working as expected? Or that I'm just missing where the output is going?

Thanks in advance for your help!

Yii Version: 1.1.13
PHP: 5.5.3
Apache
MySQL

Upvotes: 0

Views: 1965

Answers (1)

Ali MasudianPour
Ali MasudianPour

Reputation: 14459

You need to indicate to log DB like below:

'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
        array(
            'class'=>'CWebLogRoute',
            'enabled' =>TRUE,
            'categories' => 'system.db.*',
        ),
    ),
), 

You also need to remove 'levels'=>'error, warning', line which only logs errors and warnings.

You can also have both CFileLogRoute and CWebLogRoute like below:

'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
        array(
            'class'=>'CWebLogRoute',
            'enabled' =>TRUE,
            'categories' => 'system.db.*',
        ),
        array(
            'class'=>'CFileLogRoute',
            'enabled' =>TRUE,
            'categories' => 'system.db.*',
        ),
    ),
), 

Upvotes: 2

Related Questions