FirePHP extension for Yii Framework ¶
This extension contains 2 log route classes. The first, SK\Yii\FirePHP\LogRoute
, processes
standard Yii log messages. The second, SK\Yii\FirePHP\ProfileLogRoute
, processes profile summaries.
Both classes send all output to FirePHP. The classes work similarly
to CWebLogRoute
and CProfileLogRoute
.
The only major difference is the target output.
An advantage of using this extension is that logging and profiling work even through AJAX requests.
Requirements ¶
- PHP 5.4+
- A Yii Framework 1.1.14+ project.
- Firebug and FirePHP plugins for Firefox. See http://firephp.org. Firebug's Console and Net tabs have to be enabled for this to work.
- Set
output_buffering
setting to true inphp.ini
. You might also want to increase the buffer size to allow large log sizes.
Installation ¶
The only supported installation method for now is using Composer.
Put this in your
composer.json
and runcomposer update
to install it:{ "require": { "shiki/yii-firephp": "dev-master" } }
This will also automatically install the dependency firephp/firephp-core
.
Make sure you have loaded the Composer autoload file (
vendor/autoload.php
) so the libraries can be accessed in your Yii config file. See themain.php
config file in theexample
project on how this can be done.Modify your config file (e.g.
protected/config/main.php
) to include the log route classes..... 'log' => array( 'class' => 'CLogRouter', 'routes' => array( // the default (file logger) array( 'class' => 'CFileLogRoute', 'levels' => 'error, warning', ), // standard log route array( 'class' => '\\SK\\Yii\\FirePHP\\LogRoute', 'levels' => 'error, warning, info, trace', ), // profile log route array( 'class' => '\\SK\\Yii\\FirePHP\\ProfileLogRoute', 'report' => 'summary', // or "callstack" ), ), ), ....
Standard logging ¶
Once you've got the extension setup in the config, you can use Yii's logging methods to log messages to FirePHP.
// logging an INFO message
Yii::log('This is an info message.', CLogger::LEVEL_INFO);
// logging a WARNING message
Yii::log("You didn't setup a profile, are you really a person?", CLogger::LEVEL_WARNING);
// logging with a CATEGORY (categories are displayed as "labels" in FirePHP -- just an additional info text)
Yii::log('Profile successfully created', CLogger::LEVEL_INFO, 'application.user.profiles');
// tracing simple text
Yii::trace('Loading application.user.profiles.ninja', 'application.user.profiles');
// logging an ERROR
Yii::log('We have successfully determined that you are not a person',
CLogger::LEVEL_ERROR, 'Any category/label will work');
// If you need to log an array, you can use FirePHP's core methods
FB::warn(array('a' => 'b', 'c' => 'd'), 'an.array.warning');
See more about logging here.
Profiling ¶
Profiling works by simply using Yii's profiling methods.
Yii::beginProfile('a somewhat slow method');
...
// some function calls here
// more function calls
Yii::beginProfile('nested profile');
// you can also nest profile calls
Yii::endProfile('nested profile');
Yii::endProfile('a somewhat slow method'); // end
You can also profile SQL executions. See more about that and profiling in general here.
Example ¶
To try all these out, there's an example project in the example
folder. To run it:
Install the required libraries using Composer.
$ cd example $ composer install
Run with the PHP built-in webserver
$ cd example/webroot $ php -S localhost:8000
Browse http://localhost:8000 in Firefox. Make sure first that Firebug is opened and the Console and Net tabs are enabled. You should be able to see the FirePHP logs in Firebug's console. If you don't, try refreshing first.
Issues ¶
Please report issues on Github
Great!
Please make a possibility to switch on/off logging all pdo queries (add a config option?) like in Zend Framework.
Nice!
Nice extension, works great, setting 'output_buffering' to 'On' does slow things down quite a lot though.
Good job!
and standard firephp commands
and if you add this import in the main.php
'import'=>array( ...... 'application.extensions.firephp.firephp.lib.FirePHPCore.*', ),
you can use normal firephp functions in the rest of your code :
FB::send("hello world to the firebug console"); FB::info($myvar); FB::error("ups!!"); ...etc
bug fixed
PHP warning
include(FirePHP.php): failed to open stream: No such file or directory
change line 45 \protected\extensions\firephp\firephp\lib\FirePHPCore\fb.php
if(!class_exists('FirePHP')) {
to
if(!class_exists('FirePHP',false)) {
now works perfect.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.