Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
禁用特定帮助程序/库的CodeIgniter中的错误日志记录_Codeigniter_Logging_Mpdf - Fatal编程技术网

禁用特定帮助程序/库的CodeIgniter中的错误日志记录

禁用特定帮助程序/库的CodeIgniter中的错误日志记录,codeigniter,logging,mpdf,Codeigniter,Logging,Mpdf,我正在使用mPDF类从HTML生成PDF 虽然PDF显示的和它们应该显示的完全一样,但我的CodeIgniter错误日志中却塞满了错误通知,这些错误通知似乎是由于mPDF中的某些错误造成的 由于这些通知是无害的,并且PDF非常完美,所以我只想在运行此类时禁用CodeIgniter错误日志记录 但我还没有找到一个方法来做到这一点 这是我的密码: 控制器 $this->load->helper('mpdf'); mpdf($html, $filename); HELPER(mpdf_H

我正在使用mPDF类从HTML生成PDF

虽然PDF显示的和它们应该显示的完全一样,但我的CodeIgniter错误日志中却塞满了错误通知,这些错误通知似乎是由于mPDF中的某些错误造成的

由于这些通知是无害的,并且PDF非常完美,所以我只想在运行此类时禁用CodeIgniter错误日志记录

但我还没有找到一个方法来做到这一点

这是我的密码:

控制器

$this->load->helper('mpdf');
mpdf($html, $filename);
HELPER(mpdf_HELPER.php)

如您所见,我正在尝试手动将
log\u阈值的配置设置为
0
,但这并不阻止错误记录

仅供参考我的
index.php
已经

define('ENVIRONMENT', 'production');
设置错误报告(0)

你知道我应该怎么做才能阻止CodeIgniter在运行mPDF时记录错误吗

错误示例

ERROR - 2012-08-04 23:03:59 --> Severity: Notice  --> Undefined index: direction /var/www/vhosts/asd.com/httpdocs/application/helpers/mpdf/mpdf.php 21103

ERROR - 2012-08-04 23:06:07 --> Severity: Notice  --> Undefined index: MARGIN-TOP /var/www/vhosts/asd.com/httpdocs/application/helpers/mpdf/mpdf.php 17271

这是因为codeigniter的错误日志与连接,php将启动处理程序,不管错误报告值是什么。正如php手册所说:

…但是,您仍然能够读取错误报告的当前值并采取适当的行动

如果CI的内部错误级别需要日志记录,则CI的默认错误处理程序不会对日志记录执行此操作(但会对错误显示执行此操作)。(php错误处理程序调用的
log_阈值
config值1。)

如果要使CI记录器尊重错误日志记录级别,可以使用以下方法扩展CI异常类:

class MY_Exceptions extends CI_Exceptions {
    function log_exception($severity, $message, $filepath, $line) {
        $current_reporting = error_reporting();
        $should_report = $current_reporting & $serverity;

        if ($shoud_report) {
            // call the original implementation if we should report the error
            parent::log_exception($severity, $message, $filepath, $line);
        }
    }
}

一旦你准备好了,你就可以在你的库调用中或周围处理错误报告。

你能发布你收到的错误吗?您不能仅为一个区域更改错误报告-这是一个系统范围的功能这些通常是
未定义索引
错误,不会影响PDF输出--我在OP中添加了一个示例--知道如何有选择地抑制错误吗?这看起来是一个很好的解决方案--我如何使用此功能(即,我应该在我的操作代码中确切地将其称为何处)?扩展核心库的工作方式是在
application/libraries
application/core
下使用类创建一个适当命名的文件,请参见“扩展核心类”在您的情况下,将
MY_Exceptions
类代码复制到
application/core/MY_Exceptions.php
文件中,CI应自动拾取它(注意大小写字符)。
class MY_Exceptions extends CI_Exceptions {
    function log_exception($severity, $message, $filepath, $line) {
        $current_reporting = error_reporting();
        $should_report = $current_reporting & $serverity;

        if ($shoud_report) {
            // call the original implementation if we should report the error
            parent::log_exception($severity, $message, $filepath, $line);
        }
    }
}