2

I set my loggers up in my Bootstrap.php like so:

 $logger = new Zend_Log();
    if($environment->debug == '1')
    {
        $stream = @fopen('/var/www/html/rta/rta.log','a',false);
        if(!$stream){ throw new Exception('Failed to open log stream'); }
        $writer = new Zend_Log_Writer_Stream($stream);
        $logger->addWriter($writer);
        $logger->addWriter(new Zend_Log_Writer_Firebug());
    }
    else
    {
        // Do something else
    }
    Zend_Registry::set('logger',$logger);

I have the following code that I set up to fail:

$data = array(
            'config_id'      => $config->getConfigId(),
            'pass_column'    => $config->getPassColumn(),
            'filename'       => $config->getFilename(),
            'date_format'    => $config->getDateFormat(),
            'mapping_config' => $config->getMappingConfig(),
            'config_name'    => $config->getConfigName(),
            'client_id'      => $config->getClientId(),
            'description'    => $config->getDescription(),
        );

        $where = $this->getDbTable()->getAdapter()->quoteInto('config_id = ?',$config->getConfigId());
        $where = null;
        try
        {
            $this->getDbTable()->update($data,$where);
        }catch(Exception $e)
        {
            Zend_Registry::get('logger')->err('Could not update configuration.');
            Zend_Registry::get('logger')->err($e);
            return false;
        }
        return true;

I set two log writers: Stream and FirePHP. The stream log writer successfully caught and wrote the exception but FirePHP didn't do anything. If I put other log messages other places in my code, like indexAction it shows those just fine in both. Am I missing something?

EDIT The failure code is in my database mapper, not a controller. Could it be that it doesn't have access to the HTTP headers?

ashurexm
  • 6,209
  • 3
  • 45
  • 69
  • I'm not aware of how exactly does FirePHP work under ZF, but you have to remember that the data between FirePHP and Firebug are passed through headers. So if your installment of Zend catches all the header setting calls (which include FirePHP) and terminates without actually setting them before output, the data passed will be lost. – mhitza Aug 17 '10 at 22:33
  • @mhitza - I assume that this or something related is what is affecting it. In cases where I've tried to log and then do die() or other such I've seen the same issue. Googling around hasn't revealed much information on the underlying mechanics of the Firebug log writer – ashurexm Aug 18 '10 at 17:58
  • FirePHP logger does not work if you `die` or `exit` - could this be it? – Jake N Sep 04 '10 at 12:04
  • 1
    @jakenoble - Through testing I have figured out that FirePHP doesn't work upon die or exit, but do you have a source to site as to why? I have seen little documentation for FirePHP at all. – ashurexm Sep 05 '10 at 16:55

1 Answers1

1

The following example below shows how to make FirePHP get the header info it needs without using the FrontController.

    // create the logger and log writer
    $writer = new Zend_Log_Writer_Firebug();
    $logger = new Zend_Log($writer);

    // get the wildfire channel
    $channel = Zend_Wildfire_Channel_HttpHeaders::getInstance();

    // create and set the HTTP response
    $response = new Zend_Controller_Response_Http();
    $channel->setResponse($response);

    // create and set the HTTP request
    $channel->setRequest(new Zend_Controller_Request_Http());

    // record log messages
    $logger->info('info message');
    $logger->warn('warning message');
    $logger->err('error message');

    // insert the wildfire headers into the HTTP response
    $channel->flush();

    // send the HTTP response headers
    $response->sendHeaders();
?>
ashurexm
  • 6,209
  • 3
  • 45
  • 69