在CodeIgniter中,如何将PHP错误消息通过电子邮件发送给我? [英] In CodeIgniter, How Can I Have PHP Error Messages Emailed to Me?

查看:76
本文介绍了在CodeIgniter中,如何将PHP错误消息通过电子邮件发送给我?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过电子邮件接收错误日志。例如,如果出现警告级别错误消息,我想收到一封有关它的电子邮件。

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.

如何在CodeIgniter中使用它?

How can I get that working in CodeIgniter?

推荐答案

您可以扩展Exception核心类来做到这一点。

You could extend the Exception core class to do it.

可能必须调整对CI电子邮件类别的引用,不确定是否可以从这样的库中实例化它。我自己没有使用CI的电子邮件课程,我一直在使用Swift Mailer库。

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.

制作一个文件MY_Exceptions.php并将其放在/ application / libraries /中(对于CI,则放在/ application / core /中) 2)

Make a file MY_Exceptions.php and place it in /application/libraries/ (Or in /application/core/ for CI 2)

class MY_Exceptions extends CI_Exceptions {

    function __construct()
    {
        parent::__construct();
    }

    function log_exception($severity, $message, $filepath, $line)

    {   
        if (ENVIRONMENT === 'production') {
            $ci =& get_instance();

            $ci->load->library('email');
            $ci->email->from('your@example.com', 'Your Name');
            $ci->email->to('someone@example.com');
            $ci->email->cc('another@another-example.com');
            $ci->email->bcc('them@their-example.com');
            $ci->email->subject('error');
            $ci->email->message('Severity: '.$severity.'  --> '.$message. ' '.$filepath.' '.$line);
            $ci->email->send();
        }


        parent::log_exception($severity, $message, $filepath, $line);
    }

}

这篇关于在CodeIgniter中,如何将PHP错误消息通过电子邮件发送给我?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆