在我的CI配置文件中,我设置了此日志记录阈值:
$config['log_threshold'] = 1;
Run Code Online (Sandbox Code Playgroud)
在index.php中,我设置了以下错误报告:
error_reporting(E_ERROR);
Run Code Online (Sandbox Code Playgroud)
我的期望是,这将记录我记录(使用log_message('error','my error message')
)的任何CI错误,以及任何PHP错误.但是,我希望它不会记录PHP通知,只会记录错误.但是,当我查看日志文件时,它似乎也记录了PHP通知:
错误 - 2009-12-18 13:21:50->严重性:注意 - >未定义变量:pageindex /var/www/apps/OS4W/system/application/views/user/view.php 12
错误 - 2009-12- 18 13:21:50->严重性:注意 - >未定义的变量:friendsmode /var/www/apps/OS4W/system/application/views/user/activitytable.php 207
虽然日志行以"ERROR"开头,但实际上这似乎是一个PHP通知,有点像警告,我不想记录.如何确保仅记录CI和PHP错误,而不是PHP通知?我以为error_reporting(E_ERROR)
会这样做?
Fer*_*Fer 13
首先,谢谢大家一起思考.在考虑了你的建议之后,我决定修补CI的核心.不幸的是,核心类可以扩展,但不是核心本身.因此,如果您应用相同的修补程序,请务必记录它.
开始.在system\application\config\config.php中,我在log_treshold设置下面添加了以下自定义配置设置:
/*
|--------------------------------------------------------------------------
| Error Logging Exclusions (custom config addition by Ferdy Christant)
|--------------------------------------------------------------------------
|
| By default, CI will log all PHP errors, whether it is a notice, warning
| or error. Or, by setting the above treshold to 0, it will log nothing
| In most cases, however, you will want to log PHP errors but not the notices
| In the array below, simply place the PHP error constant that you do NOT
| want to see logged.
|
| For a live site you'll usually use the config as follow:
|
| $config['exclude_logging'] = array(E_STRICT,E_NOTICE);
|
*/
$config['exclude_logging'] = array(E_STRICT,E_NOTICE);
Run Code Online (Sandbox Code Playgroud)
由于文档介绍,在此配置数组你把你的PHP错误类型不希望记录.
接下来,我修补了核心文件(system/codeigniter/Common.php)并编辑了函数_exception_handler
有两个变化.首先,我将配置加载行移动到方法的顶部,因为我之前需要它.找到下面的行,你会看到$ config =&get_config(); 在它下面.删除它.
我删除了//我们应该记录错误吗?没有?我们完成了......
其次,修改严重性检查以检查我们声明的数组.转到方法的顶部,并用以下内容替换检查$ severity == E_STRICT的if语句:
$config =& get_config();
if (in_array($severity,$config['exclude_logging']))
{
return;
}
Run Code Online (Sandbox Code Playgroud)
这些补丁允许对PHP错误记录进行细粒度控制.正常的CI日志记录当然仍然有效.如上所述,唯一的缺点是这会破坏核心.
我希望这可以帮助任何人.谢谢你的思考!
对于其他可能遇到CodeIgniter 2.0的人.问题仍然存在,但解决方案"更容易".
您仍然需要修改核心文件: /system/codeigniter/Common.php
找到_exception_handler()
函数(应该在底部),并更改此行:
if ($severity == E_STRICT)
对此: if ($severity == E_STRICT OR $severity == E_NOTICE)
有趣的是他们认为E_STRICT
通知会填满日志; 但E_NOTICE
不会.或者,在使用它们之前惩罚不严格编码并声明所有变量的人可能会很好吗?:)