问题描述
我正在尝试从我的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,
有没有办法有错误日志返回错误的文件位置?
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错误日志不包括文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!