[英]Logging all the errors,warning and notices in PHP Automatically
我正在寻找一种方法,其中所有错误都将使用一行代码自动记录下来。 如果您了解Asp.NET,则可能知道我的意思是使用Application_Error
事件处理程序。
我检查了PHP日志记录框架吗? SO中的问题,但它们看起来都一样,您应该手动记录每条日志消息,这意味着我需要在要记录的任何地方调用log函数。
我正在寻找的不是这样的东西(由KLogger使用)
require_once 'KLogger.php';
...
$log = new KLogger ( "log.txt" , KLogger::DEBUG );
// Do database work that throws an exception
$log->LogError("An exception was thrown in ThisFunction()");
// Print out some information
$log->LogInfo("Internal Query Time: $time_ms milliseconds");
// Print out the value of some variables
$log->LogDebug("User Count: $User_Count");
您可以在PHP中创建自己的自定义错误处理程序函数,并将其设置为错误处理程序
就像是:
function handle_error($error_level,$error_message)
{
/*
here do what you want...typically log it into db/file/send out
emails based on error level etc..
*/
}
并将此功能设置为PHP的默认错误处理程序,请添加以下行:
set_error_handler("handle_error");
PHP现在将根据handle_error
内编写的内容处理所有错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.