導航:首頁 > 編程語言 > phpdebug日誌

phpdebug日誌

發布時間:2024-03-08 00:23:41

php能不能像java那樣列印錯誤堆棧信息到錯誤日誌

PHP 確實不會輸出錯誤堆棧,但通過函數,還是能夠獲取到錯誤堆棧的。
function getBacktrace() {
ob_start();
debug_print_backtrace();
return ob_get_clean();
}

調用上面這個函數取得錯誤堆棧,再用 file_put_contents('log_path', FILE_APPEND); 寫入日誌文件即可。
還有一個辦法:為 PHP 安裝 xdebug 擴展
windows 下的安裝方法 安裝好後,修改 php.ini

❷ php如何捕獲fatal error並寫入日誌

兩者配合,即可捕獲fatal error並寫入日誌 <?php register_shutdown_function(a); set_error_handler(b); function b($error,$message,$file,$line){ global $log; $log=array(); switch($error) { case E_ERROR: $type='ERROR'; break; case E_WARNING: $type='WARNING'; break; case E_NOTICE: $type='NOTICE'; break; default: $type='Unknown error type ['.$error.']'; break; } $log[] = date('Y-m-d H:i:s', time())."\t".$type.': '.$message.' in line '.$line.' of file '.$file.', PHP '.PHP_VERSION.' ('.PHP_OS.')'; if(function_exists('debug_backtrace')) { $backtrace=debug_backtrace(); for($level=1;$level<count($backtrace);$level++) { $message='File: '.$backtrace[$level]['file'].' Line: '.$backtrace[$level]['line'].' Function: '; if(IsSet($backtrace[$level]['class'])) $message.='(class '.$backtrace[$level]['class'].') '; if(IsSet($backtrace[$level]['type'])) $message.=$backtrace[$level]['type'].' '; $message.=$backtrace[$level]['function'].'('; if(IsSet($backtrace[$level]['args'])) { for($argument=0;$argument<count($backtrace[$level]['args']);$argument++) { if($argument>0) $message.=', '; $message.=serialize($backtrace[$level]['args'][$argument]); } } $message.=')'; $log[]=$message; } } } function a(){ global $log; if ($e = error_get_last()) { $log[] = $e['message'] . " in " . $e['file'] . ' line ' . $e['line']; } print_r($log); //還可以干一些其他的事情哦,比方說發郵件 } $a = $_GET['ss']; $a = new b();

閱讀全文

與phpdebug日誌相關的資料

熱點內容
二進制流轉pdf 瀏覽:913
php判斷爬蟲 瀏覽:567
960除24除4簡便演算法 瀏覽:786
關於解壓英語翻譯 瀏覽:565
python控制鍵盤右鍵 瀏覽:920
php沒有libmysqldll 瀏覽:828
時政新聞app哪個好 瀏覽:906
手機已加密怎麼辦 瀏覽:201
安卓手機截屏怎麼傳到蘋果 瀏覽:527
京管家app哪裡下載 瀏覽:33
文件夾橫向排列的豎向排列 瀏覽:453
51單片機驅動攝像頭模塊 瀏覽:689
政府文件加密沒法轉換 瀏覽:373
android判斷棧頂 瀏覽:331
憑證軟體源碼 瀏覽:860
androidwebview滾動事件 瀏覽:11
如何將電腦上的圖片壓縮成文件包 瀏覽:899
程序員轉金融IT 瀏覽:837
黑馬程序員培訓效果如何 瀏覽:915
本地集成編譯 瀏覽:528