If you use Firefox, I bet you already know Firebug extension. This is irreplaceable tool for web development. But there is also FirePHP extension, which provides possibility to log into Firebug console from PHP scripts. This is very convenient way for debugging process, because logs are independent from application output.

Zend Framework has really neat logging component, Zend_Log. Zend_Log is decoupled into four objects: Log, Writer, Filter and Formatter. Each of object is exchangeable. Writer is responsible for saving data. So it means, that we can save our logs anywhere we want. Into syslog, database or .. FirePHP console – we only need to use appropriate Writer. Luckily if we want to write to FirePHP console, we don’t have to create such Writer alone! In Zend Framework we can found FirebugWriter.

Using Zend_Log with FirePHP is really straightforward.

# configure logger
$logger = new Zend_Log();
$writer = new Zend_Log_Writer_Firebug();
# log into FirePHP console
$logger->log('Hello 1!', Zend_Log::INFO);
$logger->log('Hello 2!', Zend_Log::WARN);
$logger->log('Hello 3!', Zend_Log::ERR);

Notice: I assume that you have Firebug and FirePHP extensions installed.

JSON Action Helper – sendJson method

By default, JSON Action Helper sendJson method won’t work with Firebug Writer. sendJson method sends response and invoke exit function. To change this behavior (avoid exit function) , we need to set JSON Action Helper suppressExit property to true.

Writing tabular data into Firebug console

Sometimes we need to log tabular data. For example, when we use database profiler. We can achieve this with Zend_Wildfire component and Zend_Wildfire_Plugin_FirePhp_TableMessage plugin.

Example of logging tabular data.

$this->_message = new \Zend_Wildfire_Plugin_FirePhp_TableMessage('Test');
$this->_message->setOption('includeLineNumbers', false);
Zend_Wildfire_Plugin_FirePhp::getInstance()->send($this->_message, 'Test');

3 Responses to “Zend Framework: logging with Firebug and FirePHP”

  1. I am using the Zend debugger through SSH which is working fine in eclipse. I fear the overhead of setting up the hole framework.
    I’m trying to log “the other way round”, from the FB::-object to some console in the eclipse IDE, so that debugging with eclipse does not mutually exclude availability of my FirePHP-statements.

    Apart from that i don’t see the advantage of using Zend_blahblah()->send() over FB::table(), that might have to do with my above goal?

  2. exfrromtheleft says:

    i was wondering if there is a way for a transparent logging into firebug using Zf configuration and bootstrap.php. The idea is to have just one setting in application.ini to change in order to start or stop the firebug logging?

Leave a Reply →