我已经找到了如何将错误转换为异常,如果它们没有被捕获,我会很好地显示它们,但我不知道如何以有用的方式记录它们。简单地将它们写入文件不会有用,是吗?如果您还不知道导致异常的原因,您会冒险访问数据库吗?
最佳答案
你可以使用 set_error_handler设置自定义异常以记录您的错误。我个人会考虑将它们存储在数据库中,因为默认的异常处理程序的回溯可以提供有关导致它的原因的信息 - 如果数据库处理程序触发了异常,这当然是不可能的。
你也可以使用 error_log记录你的错误。它可以选择消息目的地,包括:
Quoted from error_log
- PHP's system logger, using the Operating System's system logging mechanism or a file, depending on what the error_log configuration directive is set to. This is the default option.
- Sent by email to the address in the destination parameter. This is the only message type where the fourth parameter, extra_headers is used.
- Appended to the file destination . A newline is not automatically added to the end of the message string.
编辑:markdown 有下划线的 noparse 标签吗?
关于php - 如何在 PHP 中记录未捕获的异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20322/