2013-02-07 30 views
0

我不確定如何讓FirePHP捕獲錯誤和警告並在Firebug控制檯中報告它們。如何使用FirePHP捕獲錯誤/警告

我已經安裝FirePHP,我敢肯定它是工作,我看到這些反應在控制檯:

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

我主要看「日誌信息」,「信息顯示」,「警告消息「和」錯誤消息「。然後,我改變了我的代碼,以故意打破它 - 從他們的日誌給這個對我說:

[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

有沒有你正在做的,而不是檢查傳統的PHP錯誤日誌,甚至是Web服務器錯誤日誌的一個原因? – JakeGould

+0

對於這個特定的項目,我沒有登錄權限。我受限於WordPress目錄。 –

回答

1

爲此,您需要將錯誤轉換爲例外。

從FirePHP網站:

錯誤,異常&斷言處理

轉換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:: 
} 
+0

錯誤和異常之間的差異可能是我缺少的。我會在今晚嘗試一下,同時這可能有助於其他人不清楚這一點:http://vivanet2.com/blog/119-the-important-differences-between-notices ,-warnings-exceptions-and- -errors.html –