2

我在我的 Bootstrap.php 中设置了我的记录器,如下所示:

 $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);

我有以下设置失败的代码:

$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;

我设置了两个日志编写器:Stream 和 FirePHP。流日志写入器成功捕获并写入异常,但 FirePHP 没有做任何事情。如果我将其他日志消息放在我的代码中的其他位置,就像indexAction它在两者中都显示的那样。我错过了什么吗?

编辑 失败代码在我的数据库映射器中,而不是控制器中。会不会是它无法访问 HTTP 标头?

4

1 回答 1

1

下面的例子展示了如何让 FirePHP 在不使用 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();
?>
于 2010-09-10T20:27:38.023 回答