FirePHP并不总是写日志消息 [英] FirePHP doesn't always write log messages
问题描述
我像这样在Bootstrap.php中设置记录器:
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;
我设置了两个日志编写器:Stream和FirePHP.
流日志编写器成功捕获并编写了异常,但FirePHP并未执行任何操作.如果我将其他日志消息放在代码的其他位置,例如indexAction
,则显示两者都很好.我想念什么吗?
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?
编辑 故障代码在我的数据库映射器中,而不是控制器中.可能是它无权访问HTTP标头吗?
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?
推荐答案
下面的示例显示了如何使FirePHP在不使用FrontController的情况下获取所需的标头信息.
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();
?>
这篇关于FirePHP并不总是写日志消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!