Codeigniter错误日志不包括文件名 [英] Codeigniter error log not including file name

查看:147
本文介绍了Codeigniter错误日志不包括文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的codeigniter web应用程序记录错误,我认为写入文件的消息被截断。我说这是因为每当屏幕上显示错误时,我得到错误发生的文件名,而当我检查错误日志时,它只会说,

I'm trying to log errors from my codeigniter web app and I think the messages that get written to file are getting truncated. I say this because whenever the error is displayed on screen I get the file name where the error occurred whereas when I check the error logs it only says,


查询错误:您的SQL语法有错误;检查与您的MySQL服务器版本相对应的手册,以便在第24行附近使用正确的语法。

Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 24

有没有办法有错误日志返回错误的文件位置?

Is there a way to have the error log return the file location of the error?

推荐答案

不,目前没有内置的方式在CodeIgniter中执行此操作。

No, currently there isn't a built-in way to do this in CodeIgniter.

您可以做的是扩展核心 CI_Log 类,覆盖其 write_log()方法,并使用 debug_backtrace()获取相应的文件名,并将其添加到邮件中。

What you can do is to extend the core CI_Log class, override its write_log() method and use debug_backtrace() to get the appropriate file name and prepend it to the message.


// application/core/MY_Log.php
class MY_Log extends CI_Log {

    public function write_log($level, $msg)
    {
        foreach (debug_backtrace() as $call)
        {
            // Somehow find the appropriate call here ...
            if ( ! (/* condition to ignore error-handling calls */))
            {
                break;
            }

            $msg = '['.$call['file'].'] '.$msg;
            break;
        }

        return parent::write_log($level, $msg);
    }

}

这篇关于Codeigniter错误日志不包括文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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