在 CodeIgniter 中,如何通过电子邮件将 PHP 错误消息发送给我?
我想通过电子邮件接收错误日志。 例如,如果出现警告级别
错误消息,我希望收到一封有关该错误的电子邮件。
我怎样才能让它在 CodeIgniter 中工作?
I'd like to receive error logs via email. For example, if a Warning-level
error message should occur, I'd like to get an email about it.
How can I get that working in CodeIgniter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以扩展 Exception 核心类来执行此操作。
可能需要调整对 CI 电子邮件类的引用,不确定是否可以从这样的库实例化它。 我自己不使用 CI 的电子邮件类,我一直在使用 Swift Mailer 库。 但这应该让你走上正确的道路。
创建一个文件 MY_Exceptions.php 并将其放置在 /application/libraries/ 中(对于 CI 2,则放置在 /application/core/ 中)
You could extend the Exception core class to do it.
Might have to adjust the reference to CI's email class, not sure if you can instantiate it from a library like this. I don't use CI's email class myself, I've been using the Swift Mailer library. But this should get you on the right path.
Make a file MY_Exceptions.php and place it in /application/libraries/ (Or in /application/core/ for CI 2)
该解决方案中遗漏的一件事是,您必须获取 CodeIgniters 超级对象来加载和使用电子邮件库(或任何 CodeIgniters 其他库和本机函数)。
完成此操作后,您可以使用
$CI
而不是$this
来加载电子邮件库并设置所有参数。 如需了解更多信息,请单击此处并查看在您的库中利用 CodeIgniter 资源 部分。One thing that is left out of the solution is that you have to grab CodeIgniters super object to load and use the email library (or any of CodeIgniters other libraries and native functions).
After you have done that you use
$CI
instead of$this
to load the email library and set all of the parameters. For more information click here and look under the Utilizing CodeIgniter Resources within Your Library section.哦,另一个选择是获取支持电子邮件摘要的 logrotation 应用程序。 不确定您使用的是什么平台,但您可以让某些东西监视 error_log 文件并向您发送更新,可能不太整洁,并且您肯定会仅限于 error_log 中的信息。 (error_log是Apache,CI在系统中有一个/logs/文件夹,IIS有Windows Events)
Oh, another option is to get a logrotation application that supports emailing digests. Not sure what platform you are on, but you could just have something monitor the error_log file and send you updates, might not be as neat and certainly you would be limited to only information in the error_log. (error_log is Apache, CI has a /logs/ folder in system, and IIS has the Windows Events)
我即将发布一个开源项目来实现此功能以及更多功能。 它收集错误,将其发送到问题跟踪器,检测重复项,将其转化为问题并向工作人员发送电子邮件。
详细信息请参见 https://sourceforge.net/news/?group_id=317819&id= 293422 和它提到的 0.1.7 版本将在几天内发布。
开源跟踪器位于 http://elastik.sourceforge.net/
欢迎任何反馈,谢谢
I'm just about to release an open source project that does this, and more. It collects errors, sends them to an issue tracker, detects duplicates, turns them into issues and emails staff.
Details are at https://sourceforge.net/news/?group_id=317819&id=293422 and the version 0.1.7 it mentions is due out in a couple of days.
The open source tracker is at http://elastik.sourceforge.net/
Any feedback welcome, Thanks