如何判断数据库查询或自动电子邮件等失败的系统进程是否值得向用户发送错误消息?

时间:2022-06-10 12:59:47

I'm thinking through all the points in my PHP application where it performs some sort of system process like database queries, or sending out an email, and I'm wondering if at all these points I should be notifying a user when something goes wrong. There are so many points where an application can fall apart, that I'm having trouble determining if it is worth it to notify the user. Is it better to have some sort of logging in place, where every few days I just monitor the logs? Is there a standard approach for large-scale applications?

我正在考虑我的PHP应用程序中的所有要点,它执行某种系统过程,如数据库查询,或发送电子邮件,我想知道是否在所有这些点上我应该在出现问题时通知用户。应用程序可能会分崩离析,我无法确定是否值得通知用户。是否更好地进行某种日志记录,每隔几天我就会监控日志?是否有大规模应用的标准方法?

3 个解决方案

#1


You could probably use something like log4php, which is a php-based implementation of the famous log4j library. You would then log messages whereever applicable using a 'severity'. Based on two factors - severity and category you configure 'where' and 'how' to log/process/display the messages thanks to the flexible appender system.

你可以使用像log4php这样的东西,这是一个基于php的着名log4j库的实现。然后,您将使用“严重性”记录适用的消息。基于两个因素 - 严重性和类别,您可以通过灵活的appender系统配置“在哪里”和“如何”记录/处理/显示消息。

While i'm not sure if there is already a complete solution for php, you could for instance have non-severe errors logged to a database and diplayed by admininstration component within your application, while severe errors get sent to you by e-mail and im.

虽然我不确定是否已经有完整的php解决方案,但您可以将非严重错误记录到数据库并由应用程序中的admininstration组件显示,同时严重错误通过电子邮件发送给您IM。

#2


From a user perspective everything unexpected (that includes error messages prompts like "Are you sure" or similar) triggers the urge to get rid of it as soon as possible. Users don't read messages and likely won't notify you of problems, so overwhelming a user with technical details is in almost all cases the wrong way to go and you're usually better off with logging or perhaps an e-mail to you when something goes wrong.

从用户的角度来看,一切意外(包括错误消息提示,如“你确定”或类似)会触发尽快摆脱它的冲动。用户不会阅读消息,并且可能无法通知您有问题,因此几乎在所有情况下,用技术细节压倒用户都是错误的方式,通常情况下您最好还是记录或者发送电子邮件给您什么时候出错了。

As for the user, try to divide yuor failure cases into failures that can be mitigated by retrying and retry automatically before telling the user (but not endlessly) and failures that need administrative action or simply time to solve in which case a generic error message along with a more detailed log message for the developers should be best.

至于用户,尝试将yuor失败案例划分为失败,可以通过在告诉用户(但不是无休止地)之前自动重试和重试以及需要管理操作的故障或简单地解决时间(在这种情况下是一般性错误消息)来减轻为开发人员提供更详细的日志消息应该是最好的。

That is, if you're not assuming all your users are developers.

也就是说,如果您没有假设您的所有用户都是开发人员。

#3


Ideally your users will tell you what they want to be notified about as part of your requirements process.

理想情况下,您的用户会告诉您他们希望在您的需求流程中收到通知。

Failing that, you could adopt a guideline like only notifying on situations which require some action on the user's part.

如果做不到这一点,你可以采用一个指导方针,例如仅通知需要对用户采取某些行动的情况。

#1


You could probably use something like log4php, which is a php-based implementation of the famous log4j library. You would then log messages whereever applicable using a 'severity'. Based on two factors - severity and category you configure 'where' and 'how' to log/process/display the messages thanks to the flexible appender system.

你可以使用像log4php这样的东西,这是一个基于php的着名log4j库的实现。然后,您将使用“严重性”记录适用的消息。基于两个因素 - 严重性和类别,您可以通过灵活的appender系统配置“在哪里”和“如何”记录/处理/显示消息。

While i'm not sure if there is already a complete solution for php, you could for instance have non-severe errors logged to a database and diplayed by admininstration component within your application, while severe errors get sent to you by e-mail and im.

虽然我不确定是否已经有完整的php解决方案,但您可以将非严重错误记录到数据库并由应用程序中的admininstration组件显示,同时严重错误通过电子邮件发送给您IM。

#2


From a user perspective everything unexpected (that includes error messages prompts like "Are you sure" or similar) triggers the urge to get rid of it as soon as possible. Users don't read messages and likely won't notify you of problems, so overwhelming a user with technical details is in almost all cases the wrong way to go and you're usually better off with logging or perhaps an e-mail to you when something goes wrong.

从用户的角度来看,一切意外(包括错误消息提示,如“你确定”或类似)会触发尽快摆脱它的冲动。用户不会阅读消息,并且可能无法通知您有问题,因此几乎在所有情况下,用技术细节压倒用户都是错误的方式,通常情况下您最好还是记录或者发送电子邮件给您什么时候出错了。

As for the user, try to divide yuor failure cases into failures that can be mitigated by retrying and retry automatically before telling the user (but not endlessly) and failures that need administrative action or simply time to solve in which case a generic error message along with a more detailed log message for the developers should be best.

至于用户,尝试将yuor失败案例划分为失败,可以通过在告诉用户(但不是无休止地)之前自动重试和重试以及需要管理操作的故障或简单地解决时间(在这种情况下是一般性错误消息)来减轻为开发人员提供更详细的日志消息应该是最好的。

That is, if you're not assuming all your users are developers.

也就是说,如果您没有假设您的所有用户都是开发人员。

#3


Ideally your users will tell you what they want to be notified about as part of your requirements process.

理想情况下,您的用户会告诉您他们希望在您的需求流程中收到通知。

Failing that, you could adopt a guideline like only notifying on situations which require some action on the user's part.

如果做不到这一点,你可以采用一个指导方针,例如仅通知需要对用户采取某些行动的情况。