1

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

虽然 PDF 完全按照它们应有的方式显示,但我的 CodeIgniter 错误日志中充满了错误通知,这些错误通知似乎是由于 mPDF 中的一些错误造成的。

由于这些通知是无害的,并且 PDF 输出完美,我只想在运行此类时专门禁用 CodeIgniter 错误日志记录。

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

这是我的代码:

控制器

$this->load->helper('mpdf');
mpdf($html, $filename);

助手(mpdf_helper.php)

function mpdf($html, $filename) 
{
    $CI =& get_instance();
    $CI->config->set_item('log_threshold', 0);
    include('mpdf/mpdf.php');

    $mpdf=new mPDF('', 'letter');
    $mpdf->SetHTMLHeader('powered by example.com');
    $mpdf->WriteHTML($html, 0);
    $mpdf->Output($filename, 'I');
}

如您所见,我正在尝试手动将配置设置为log_thresholdto 0,但这并不能阻止错误记录。

仅供参考我index.php

define('ENVIRONMENT', 'production');

设置error_reporting(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
4

1 回答 1

3

这是因为 codeigniter 的错误日志与set_error_handler挂钩,无论 error_reporting 值是什么,php 都会触发处理程序。正如php手册所说:

...但是您仍然能够读取 error_reporting 的当前值并采取适当的行动。

CI 的默认错误处理程序不会为日志记录(但会为错误显示)执行此操作,如果 CI 的内部错误级别需要日志记录,则只会记录所有进入的内容。log_threshold配置值为 1,php 错误处理程序调用的函数。)

如果你想让 CI 记录器尊重 error_logging 级别,你可以使用如下标准方法扩展 CI_Exception 类:

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);
        }
    }
}

一旦你完成了这个,你就可以在你的库调用中或在你的库调用中摆弄error_reporting。

于 2012-08-05T13:43:29.033 回答