PHP错误报告:屏幕上有一些错误,全部都要记录

时间:2021-07-21 00:00:09

I want to know how I can display E_ERROR error messages to the screen but write E_ALL error messages to the error log, we currently use the error_reporting() in our app index page so we can change error reporting without the need to constantly restart the web server, but it seems that this (or perhaps the way it's meant to work) means that we only log errors that we see on the screen.

我想知道如何向屏幕显示E_ERROR错误消息但是将错误消息写入错误日志,我们目前在应用程序索引页面中使用error_reporting(),这样我们就可以更改错误报告而无需不断重启Web服务器,但似乎这(或者它的工作方式)意味着我们只记录我们在屏幕上看到的错误。

Is there a way to log and display different levels of errors?

有没有办法记录和显示不同级别的错误?

Cheers!

1 个解决方案

#1


1  

You could make a custom error handler, and in your error handler check if the error is an E_ERROR; if so, print it out. Then log the error, regardless of whether it is an E_ERROR or not.

您可以创建自定义错误处理程序,并在错误处理程序中检查错误是否为E_ERROR;如果是这样,打印出来。然后记录错误,无论它是否是E_ERROR。

If you're not familiar with custom error handling, the PHP manual has a good example on how to use an error handler to do different things depending on the nature of a PHP error.

如果您不熟悉自定义错误处理,那么PHP手册就如何使用错误处理程序根据PHP错误的性质执行不同的操作提供了一个很好的示例。

#1


1  

You could make a custom error handler, and in your error handler check if the error is an E_ERROR; if so, print it out. Then log the error, regardless of whether it is an E_ERROR or not.

您可以创建自定义错误处理程序,并在错误处理程序中检查错误是否为E_ERROR;如果是这样,打印出来。然后记录错误,无论它是否是E_ERROR。

If you're not familiar with custom error handling, the PHP manual has a good example on how to use an error handler to do different things depending on the nature of a PHP error.

如果您不熟悉自定义错误处理,那么PHP手册就如何使用错误处理程序根据PHP错误的性质执行不同的操作提供了一个很好的示例。