gpt4 book ai didi

php - 有没有一种方法可以更改php的error_log(string)的错误格式?

转载 作者:行者123 更新时间:2023-12-03 08:54:04 25 4
gpt4 key购买 nike

我想知道是否可以更改php_error.log中的默认错误格式:

[12-Aug-2015 23:11:23 Europe/Berlin] information

到其他我可以更轻松地重用的东西,例如:
timestamp;information;otherinformation

不使用设置错误处理程序。

最佳答案

您需要define your own error handler:

function myErrorHandler($errno, $errstr, $errfile, $errline)
{
if (!(error_reporting() & $errno)) {
// This error code is not included in error_reporting
return;
}

switch ($errno) {
case E_USER_ERROR:
echo "<b>My ERROR</b> [$errno] $errstr<br />\n";
echo " Fatal error on line $errline in file $errfile";
echo ", PHP " . PHP_VERSION . " (" . PHP_OS . ")<br />\n";
echo "Aborting...<br />\n";
exit(1);
break;

case E_USER_WARNING:
echo "<b>My WARNING</b> [$errno] $errstr<br />\n";
break;

case E_USER_NOTICE:
echo "<b>My NOTICE</b> [$errno] $errstr<br />\n";
break;

default:
echo "Unknown error type: [$errno] $errstr<br />\n";
break;
}

/* Don't execute PHP internal error handler */
return true;
}

// function to test the error handling
function scale_by_log($vect, $scale)
{
if (!is_numeric($scale) || $scale <= 0) {
trigger_error("log(x) for x <= 0 is undefined, you used: scale = $scale", E_USER_ERROR);
}

if (!is_array($vect)) {
trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
return null;
}

$temp = array();
foreach($vect as $pos => $value) {
if (!is_numeric($value)) {
trigger_error("Value at position $pos is not a number, using 0 (zero)", E_USER_NOTICE);
$value = 0;
}
$temp[$pos] = log($scale) * $value;
}

return $temp;
}

// set to the user defined error handler
$old_error_handler = set_error_handler("myErrorHandler");

现在,您的 error_log调用将使用定义的格式。

关于php - 有没有一种方法可以更改php的error_log(string)的错误格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31975590/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com