When developing an application there are some important factors that you have to pay close attention to avoid problems in the future. I think one of the most important is logging information on how your application is working and when it fails.
Through Wildfire, a project that was created to help developers have a standard way for sending messages between different programming languages and scripts. The Zend Framework is now able to communicate to the Firebug console in order to display logging messages injected by PHP.
Using this component is pretty straight forward if you are using Zend_Controller_Front (MVC) with zend Framework.
Place this in your bootstrap file before dispatching your front controller
$writer = new Zend_Log_Writer_Firebug(); $logger = new Zend_Log($writer);
Then whenever you want to log something to Firebug just use it in your model, view, or controller like this.
$logger->log('This is an INFORMATIONAL log message!', Zend_Log::INFO); $logger->log('This is a WARNING log message!', Zend_Log::WARN); $logger->log('This is an ERROR log message!', Zend_Log::ERROR);
If you notice in the example above, you can specify the type of message you want to log (INFO, WARN, etc..). This is helpful when you want to clearly identify what type of message you are viewing since it will apply a special formatting and in some instances provide more information.
If you want to use the Zend_Log_Writer_Firebug as a stand alone here is the sample code you can use:
//Instantiate the Firebug Writer $writer = new Zend_Log_Writer_Firebug(); $logger = new Zend_Log($writer); //start the wildfire component $request = new Zend_Controller_Request_Http(); $response = new Zend_Controller_Response_Http(); $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance(); $channel->setRequest($request); $channel->setResponse($response); // Start output buffering ob_start(); // Now you can make calls to the logger $logger->log('This is a log message!', Zend_Log::INFO); // Flush log data to browser $channel->flush(); $response->sendHeaders();
If you don’t use ZendFramework there is another alternative to php developers. FirePhp, will also enable you to send log messages to Firebug by using php method calls. Be sure to check FirePhp website to get more information.
So remember that this is just one easy and great way to debug your projects, there are many other tools and methods you can incorporate into your projects. If you want to share other ways or simply just want to ask a question regarding this post, feel free to leave a comment.