怎么让php打印错误日志
2个回答
展开全部
要捕获错误的话,一般都要自己封装一下
代码示例:
<?php
//error handler function
function customError($errno, $errstr, $errfile, $errline)
{
echo "<b>Custom error:</b> [$errno] $errstr<br />";
echo " Error on line $errline in $errfile<br />";
echo "Ending Script";
die();
}
//set error handler
set_error_handler("customError");
$test=2;
//trigger error
if ($test>1)
{
trigger_error("A custom error has been triggered");
}
?>
输出:
Custom error: [1024] A custom error has been triggered
Error on line 19 in C:\webfolder\test.php
Ending Script
具体参考:http://www.w3school.com.cn/php/func_error_set_error_handler.asp
代码示例:
<?php
//error handler function
function customError($errno, $errstr, $errfile, $errline)
{
echo "<b>Custom error:</b> [$errno] $errstr<br />";
echo " Error on line $errline in $errfile<br />";
echo "Ending Script";
die();
}
//set error handler
set_error_handler("customError");
$test=2;
//trigger error
if ($test>1)
{
trigger_error("A custom error has been triggered");
}
?>
输出:
Custom error: [1024] A custom error has been triggered
Error on line 19 in C:\webfolder\test.php
Ending Script
具体参考:http://www.w3school.com.cn/php/func_error_set_error_handler.asp
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询