【问题标题】:How to turn off magento error reporting magento/var/report/如何关闭magento错误报告magento/var/report/
【发布时间】:2012-03-27 15:21:51
【问题描述】:

我正在使用 magento。它不断在 magento/var/report 文件夹中生成错误报告文件。

它不是一个单独的日志文件,而是每天生成数千个文件

magento 中有什么方法可以关闭该功能吗?

【问题讨论】:

  • 什么版本的 Magento?我认为没有任何最新版本使用过该目录。
  • 如果“每天生成数千个文件”,听起来会有大问题。有哪些错误?您可以通过简单地从 var/report 中删除写权限来停止生成这些文件,但我认为这不是真正的解决方案。
  • 确实如此。这些文件不大。大多数错误是由于一个magento目录中的多个店面。 magento 中必须有办法关闭这些错误报告。
  • 只需截断errors/report.php 文件并将header() 放在那里并重定向到您的主页。你应该处理那些“数千人”!

标签: magento


【解决方案1】:

(我目前没有安装 1.4.0.1,但我认为这几乎都是一样的)

对此没有配置设置。您需要自定义代码来实现这一点(假设政治/能力/预算阻止了明显的解决方案,即修复错误)。

这些错误是在一段 Magento 代码调用时产生的

Mage::printException($e);

这个方法,最终是report.php文件中的requires。

public static function printException(Exception $e, $extra = '')
{
    //...snip...
    require_once(self::getBaseDir() . DS . 'errors' . DS . 'report.php');
}

而report.php 包含以下内容

#File: errors/report.php
require_once 'processor.php';

$processor = new Error_Processor();

if (isset($reportData) && is_array($reportData)) {
    $processor->saveReport($reportData);
}

$processor->processReport();

这是对saveReport 的调用,它保存了让您烦恼的文件

public function saveReport($reportData)
{
    $this->reportData = $reportData;
    $this->reportId   = abs(intval(microtime(true) * rand(100, 1000)));
    $this->_reportFile = $this->_reportDir . '/' . $this->reportId;    
    //...snip...
    @file_put_contents($this->_reportFile, serialize($reportData));
    //...snip...
}

在这个执行链中没有任何地方(我保证即使是在被截断的代码中)也没有在写入文件或调用printException 之前检查配置的条件代码。这意味着实现您想要的唯一方法是手动修改文件。

如何由你决定,如果是我,我会注释掉 file_put_contents 行。

#@file_put_contents($this->_reportFile, serialize($reportData));

这是单行更改,但商店的现有行为保持不变。

说了这么多——真正的解决方案是修复错误。

【讨论】:

    【解决方案2】:

    错误报告是一种有价值的工具,禁用它会从开发人员工具包中删除一个非常有用的资源。我会尝试修复报告的错误,而不是隐藏日志本身。

    也就是说,您可以通过以下两种方式之一禁用此错误报告。我推荐第一个,但如果您在生产环境中,您可能不想向所有人显示错误消息。

    1. 开启开发者模式。这会将错误消息放在页面上,并且不会生成 var/report 中的文件。有几种方法可以做到这一点,这里是一种:

      // In index.php, after Magento is loaded but before Mage::run();
      Mage::setIsDeveloperMode(true);
      
    2. 修改 var/report 的权限,使 web 服务器用户(www-data、apache,取决于您的设置)没有写入权限。

      # If the directory is not owned by www-data this is sufficient, otherwise
      # change go-w to a-w
      $ chmod go-w var/report
      

    【讨论】:

      【解决方案3】:

      添加以下行

      需要一次 MAGENTO_ROOT 。 DS 。 “错误”。 DS 。 'report.php';

      $x = $y + $z;

      行后

      require_once $mageFilename;

      在index.php页面中,这会强制将错误显示在report.php中

      【讨论】:

        【解决方案4】:

        这是你需要做的,去:System -> Configuration -> Advanced - > Developer -> Log Settings -> Enabled = 'No'。

        如果您指的是日志表,则需要添加一个 cron 来清理它。我可以给你更多细节,如果是这样的话,请告诉我。

        【讨论】:

        • 不,这不正确。日志设置不影响 var/report 中的错误报告
        • 是的,你是对的,我的错。这将禁用日志记录而不是错误报告。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-05
        • 2015-05-26
        • 1970-01-01
        • 2014-06-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多