如何使用FirePHP捕获错误/警告

时间:2013-02-07 01:35:47

标签: php debugging firephp

我不确定如何让FirePHP捕获错误和警告并在Firebug控制台中报告它们。

我已经安装了FirePHP,我很确定它正在运行 - 我在控制台中看到了这些响应:

fb('Log message', FirePHP::LOG);
fb('Info message', FirePHP::INFO);
fb('Warn message', FirePHP::WARN);
fb('Error message', FirePHP::ERROR);

我基本上看到“日志消息”,“信息消息”,“警告消息”和“错误消息”。然后我改变了我的代码以故意破坏它 - IT从他们的日志中给我这个:

[21-Jan-2013 22:19:49] PHP Warning:  Missing argument 3 for
echo_first_image(), called in
/app/web/xxx/wp-content/themes/xxx/home.php on
line 85 and defined in
/app/web/xxx/wp-content/themes/xxx/functions.php
on line 12

我正试图在FirePHP中捕获并打印它,但它没有被检测到,我不确定为什么。我的初始化FirePHP的完整代码块:

<?php /* debug */
require_once("debug/FirePHP.class.php");
require_once('debug/fb.php');
$firephp = FirePHP::getInstance(true);
ob_start();
fb('Log message', FirePHP::LOG);
fb('Info message', FirePHP::INFO);
fb('Warn message', FirePHP::WARN);
fb('Error message', FirePHP::ERROR);
?>

解释或资源会有所帮助。谢谢!

1 个答案:

答案 0 :(得分:1)

为此,您需要将错误转换为例外。

来自FirePHP网站:

  

错误,异常&amp;断言处理

     

转换E_WARNING,E_NOTICE,E_USER_ERROR,E_USER_WARNING,   E_USER_NOTICE和E_RECOVERABLE_ERROR错误到ErrorExceptions和   如果需要,可以自动将所有例外信息发送给Firebug。

     

如果需要,可以将断言错误转换为异常并抛出。

     

您也可以手动将捕获的例外发送给Firebug。

$firephp->registerErrorHandler(
            $throwErrorExceptions=false);
$firephp->registerExceptionHandler();
$firephp->registerAssertionHandler(
            $convertAssertionErrorsToExceptions=true,
            $throwAssertionExceptions=false);

try {
  throw new Exception('Test Exception');
} catch(Exception $e) {
  $firephp->error($e);  // or FB::
}