The FDbWebLogRoute is a CWebLogRoute extension solely for logging SQL queries. While you can log ALL the SQL using Yii profiling (See http://www.yiiframework.com/doc/guide/1.1/en/topics.logging#profiling-sql-executions) this could be prettier with FDbWebLogRoute because the profiler always gives you a start and a end log for each query. It means you see one query twice.
This logroute also use Google code prettier JS library to beautify the SQLs a bit. Some color and highlighting to save your eyes.
Requirements ¶
Google code prettier library. This is not distributed with the extension. Download is here: http://code.google.com/p/google-code-prettify/
Usage ¶
The intension of this extension is for debugging your SQL. If you need profiling, identify the bottleneck SQL, do use Yii profiling.
To log a query:
dbLogBegin();
Post::model()->findAll();
dbLogEnd();
Same way of dbLogBegin/End wrapping your code to log all queries executed in the code block. i.e. put these function at the begin and end of your controller's action.
Deployment ¶
Put this file under extensions/logging/ folder
Put Google code prettify library under extensions/scripts/code.prettify (rename the 'src' folder in your download by 'code.prettify'). If this is not what you want, edit line #58, #59 in FDbWebLogRoute.php
Configuration:
// db component in config/main.php
'db' => array(
...
'enableProfiling'=>true, //optional, if you also need profiling
'enableParamLogging'=>true, //to show parameter values
),
// log component in config/main.php
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
...
'dbLog' => array(
'class' => 'ext.logging.FDbWebLogRoute', //if you put this file under extensions/logging/ fodler
),
),
Looks like it has good potential
I haven't been able to get this to work reliably. There are some gaps in the documentation here that could be clarified. First:
put the Google library under extensions/assets/scripts/code.prettify
Also, the deployment is not clear. Why is there a 'dbLog'=> in the routes config? routes don't usually look like that. See here. It makes me think there is perhaps something else missing?
Nice start here.
Greg
Re: Looks like it has good potential
You're right about the prettify location.
The log routes usually don't need to have name but there is nothing wrong with it. The dbLog is a key of DB log route we need to refer to in the code. Yii doesn't care whether the log route configuration use numeric (by default) or string key.
Definitely potential
I also had some issues getting this to work. Doesn't seem like Yii is publishing the prettify code correctly. No js or css file got created in my assets/a324234/scripts/code.prettify folder (but it did create the folder?). Who knows, i'm still new to Yii. So I moved those 2 files to that folder and it works.
Side note, this worked nice for making the SQL queries even easier to read.
Add:
$('.pln:contains("WHERE")').before('<br />'); $('.pln:contains("SELECT")').before('<br />'); $('.pln:contains("FROM")').before('<br />'); $('.pln:contains("LEFT")').before('<br />'); $('.pln:contains("INNER")').before('<br />'); $('.pln:contains("LIMIT")').before('<br />'); $('.pln:contains("ORDER")').before('<br />');
etc
after line 63 of FDbWebLogRoute.php
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.