Question: How do I set up logging with FirePHP in Zend Framework?
Answer:
- Step 1: Make sure you have Zend Framework 1.6+
- Step 2: Install both Firebug and FirePHP extensions for Firefox.
- Step 3: Make sure you have Console and Net enabled.\
- Step 4: Set up Zend Log in your bootstrap file:
$writer = new Zend_Log_Writer_Firebug(); $logger = new Zend_Log($writer);
You can now send a log message to Firebug with the following code (in your bootstrap file):
$logger->log('Hello World!', Zend_Log::DEBUG);
If you wanted to use the logger outside of your bootstrap file, you can set $logger in the session:
Zend_Registry::set('logger', $logger);
$logger = Zend_Registry::get('logger');
$logger->log('This is my log message', Zend_Log::INFO);
However, when I want to debug, I don’t want a bunch of lines or characters when I just want to output something to the logger. So I prefer to make a function in my bootstrap file that can be used throughout my application:
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);
Zend_Registry::set('logger', $logger);
function debug($message) {
$logger = Zend_Registry::get('logger');
$logger->debug($message);
}
That way, in my I can use by simply calling:
debug('hello!');
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.