Debugging Laravel with MonoLog and FirePHP

By default, Laravel is configured to create daily log files for your application, and are stored in app/storage/logs. All Laravel logging features are handled by the wonderful MonoLog library. Monolog includes various log handlers you can use – FirePHP, ChromePHP, CouchDB, Stream and many more. One of my favorites is FirePHP while debugging PHP apps.

By default Monolog is enabled in Laravel and we can just log any content easily. The following lines log the data to the logs files in app/storage/logs.

Log::info('General information log');
Log::warning('Warning log');
Log::error('Error log');

This will add the following lines to the log file.

[2013-06-07 06:23:14] log.INFO: General information log [] []
[2013-06-07 06:23:14] log.WARNING: Warning log [] []
[2013-06-07 06:23:14] log.ERROR: Error log [] []

To add FirePHP support for debugging you need to add a handler to Monolog. For that we first need to get a Monolog instance from Laravel and then add a FirePHP handler.

$test_data = array('var1' => 'test data1', 'var2' => 'test data 2');
 
/* Get Monolog instance from Laravel */
$monolog = Log::getMonolog();
 
/* Add the FirePHP handler */
$monolog->pushHandler(new \Monolog\Handler\FirePHPHandler());
 
/* Log information */
$monolog->addInfo('Log Message', $test_data);

You can now view the above logs in your FireBug console. Make sure that FirePHP extension for FireFox is installed.



3 thoughts on “Debugging Laravel with MonoLog and FirePHP

  1. I tried this and have the FirePHP extensions installed and enabled, but i’m not sure why the log messages won’t show up in the console…Any help…

Comments are closed.