This log route tries to solve and add the missing part of the CWebLogRoute.
CWebLogRoute is a great way to get interesting information on the web page but it has it's drawbacks. First of all it display the log every time and it outputs the log on the end of the generated web page and this can make more trouble than good.
The log is placed after the ending html directive, this way it makes non valid HTML markup, and by looking at the web page source you can see the whole long log appended at the end. This troubles me many times while developing. When I want to see the JS code generated by Yii, by going to the end of the file I expect to see the JS code but instead there is the whole log that I need to scroll upward to find the JS code.
Two things I miss most from CWebLogRoute is the possibility to decide when I want to see the log and to see logs from an AJAX call.
That's how the idea of the AWFLogRoute was born.
The main points of this log route is to have valid HTML syntax, clean HTML, show logs only on request and the possibility to show logs for AJAX requests.
When this route is used, the only code added to the web page is a small JS code that generates a button that is used to display the application log. No log data is on the web page, the log is instead saved on a file on the server. In that file there is just the log of the last processed request. If the developer needs to see the application logs for the just executed request, he just needs to click the "Load Application Log" button. At that time an ajax request is executed that gets the logs from the log file and the log is shown on the web page. By clicking "Re-Load Application Log" the log is reloaded with the logs from the last processed request. This can be used after any AJAX request like CGridView pagination, filtering or sorting.
Requirements ¶
- jQuery 1.7 (the new "on" method is used)
- developed on Yii 1.1.9 that has jQuery 1.7 as part of the core
Usage ¶
- create a new sub-folder AWFLog in the /protected/components folder
- download the ZIP file and place the content (2 php files) in the new folder (/protected/components/AWFLog)
- configure your application to use this route by modifying the config file (/protected/config/main.php)
Config example:
...
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
...
array(
'class' => 'application.components.AWFLog.AWFLogRoute',
),
),
),
...
Update v.0.3
Now it's possible to set the alias for the controller of this extension. This is useful if you place the extension in a folder other than /protected/components/awflog.
For example if you place this extension in the /protected/extension/awflog folder than you can use this settings:
...
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
...
array(
'class' => 'ext.AWFLog.AWFLogRoute',
'controllerAlias' => 'ext.AWFLog',
),
),
),
...
Options ¶
- logPath - the directory where the log file will be stored. Defaults to application runtime path.
- logFile - name of the log file. Defaults to 'awflogroute.log'.
- controllerAlias - the directory alias where the AWF Log controller is located. Defaults to 'application.components.AWFLog.AWFLogController'.
Styling ¶
The generated buttons and log content can be styled with custom CSS. These are the used IDs
- AWFLogBtn - DIV that holds the 2 buttons
- AWFLogBtnShow - "Load Application Log" button
- AWFLogBtnHide - "Remove Application Log" button
- AWFLogData - DIV that holds the log data
Changelog ¶
- 29.02.12 15:30 - version 0.3
- added controllerAlias attribute (see above the update v.0.3 for more info)
- 28.12.11 16:00 - version 0.2
- added data parameter when enableCsrfValidation is used
- added details of the request (uri, type and AJAX)
- 22.12.11 23:40 - version 0.1
- fixed JS code rendering
- now it's possible to manually add the buttons and/or the data container
- 22.12.11 15:00 - initial release
Discussion ¶
For discussion about this extension follow this forum thread.
nice
Sounds really nice, could you please attach some screenshots or upload a demo? I dont like downloading+installing just to see how it looks like.
Re: nice
As this is just a log route that replaces CWebLogRoute I really don't see the point in uploading screenshots or even a whole demo. If you ever used CWebLogRoute this is the same...
The difference is that you don't see the log on the page until you click on the button "Load Application Log"...
enableCsrfValidation=>true
mdomba, thank you for this extension!
I use 'enableCsrfValidation'=>true and to make all works properly I added a parameter "data" into ajax request in the AWFLogRoute::init():
$request=Yii::app()->getRequest(); $data=$request->enableCsrfValidation ? ',data:{'.$request->csrfTokenName.':"'.$request->csrfToken.'"}' : ''; $js='(function(){var a,b,c...{$.ajax({url:"'.$url.'",type:"POST"'.$data.',success:function(d)...
Re: enableCsrfValidation=>true
Thanks Alexey
I updated the extension to incorporate your code, and added more information about the request... now at the top the requested URI is displayed together with the request type (GET,POST,...) and the green word AJAX if the log is for an AJAX request.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.