marcusj
(Marcusj)
October 16, 2009, 2:44pm
1
Is there a possibility to display (i.e. via CWebLogRoute) all executed SQL statements in a detailled/complete way?
Right now I get this information only if there is an exception. In any other case it only displays a information like 'SHOW CREATE TABLE ContactsProfile
'. The queries are defined as models in the function relations().
Thx
Marcus
Allready checked this forum but found only the CWebLogRoute way…
tri
(tri - Tommy Riboe)
October 16, 2009, 3:02pm
2
See http://www.yiiframework.com/doc/guide/topics.logging
"By setting CDbConnection::enableProfiling to be true in the application configuration, every SQL statement being executed will be profiled. The results can be readily displayed using the aforementioned CProfileLogRoute, which can show us how much time is spent in executing what SQL statement. "
Also add enableParamLogging
'db'=>array(
'connectionString'=>...
'enableParamLogging'=>true,
'enableProfiling'=>true,
),
Under some circumstances logging to a file will give you information not visible in the web page.
CProfileLogRoute example:
'components'=>array(
'log'=>array(
...
array(
'class'=>'CProfileLogRoute',
'report'=>'summary',
),
...
/Tommy
marcusj
(Marcusj)
October 16, 2009, 4:10pm
3
Hi Tommy,
thanks for the quick reply. Except for ‘summray’ I think I had everything in my main.php:
'db'=>array(
'class'=>'CDbConnection',
..
'enableProfiling' => true,
'enableParamLogging' => true,
),
....
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
'web'=>array(
'class'=>'CWebLogRoute',
'levels'=>'trace, info, error, warning',
'categories'=>'system.db.*',
'showInFireBug'=>false //true/falsefirebug only - turn off otherwise
),
'file'=>array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning, watch',
'categories'=>'system.*',
),
'profile'=>array(
'class' => 'CProfileLogRoute',
'report'=>'summary',
But I still get only errors displayed or the above mentioned short version…
Any other idea?
Thx
Marcus
tri
(tri - Tommy Riboe)
October 16, 2009, 4:33pm
4
I’m not sure your key=>value syntax will work. My log setup is as follows. Haven’t used it recently. I assume you already found the log file in protected/runtime.
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
//'levels'=>'error, warning',
'levels'=>'trace, info, error, warning',
),
array(
'class'=>'CProfileLogRoute',
'report'=>'summary', /* summary or callstack */
),
),
),
Edit:
Since you have the web logging working I also assume you preload the log component.
return array(
...
'preload'=>array('log'),
...
marcusj
(Marcusj)
October 16, 2009, 5:07pm
5
I think my syntax is working since there is a weblog, but it does not show the complete SQL statement for all excecuted queries…
19:23:48.661820 trace system.db.CDbConnection Opening DB connection
19:23:48.690167 trace system.db.CDbCommand Querying SQL: SHOW COLUMNS FROM `User`
19:23:48.711076 trace system.db.CDbCommand Querying SQL: SHOW CREATE TABLE `User`
19:23:48.732249 trace system.db.CDbCommand Querying SQL: SHOW COLUMNS FROM `ContactsProfile`
19:23:48.744143 trace system.db.CDbCommand Querying SQL: SHOW CREATE TABLE `ContactsProfile`
May my problem is that I define the queries in the function relations():
19:40:49.445883 trace system.db.ar.CActiveRecord lazy loading User.contactprofile
Marcus
marcusj
(Marcusj)
October 16, 2009, 9:59pm
6
Ok, wrong thinking.
The SQL I was looking for was not executed because master-query-result was NULL and therefore did not start relations-command…
Log is working fine.
Sorry
Marcus