Magento 2 update.log每分钟都会增加大量文件


9

更新:

我最终使用logrotate实用程序来处理不断增长的日志文件。我还设置了一些cron作业,这些作业将不时检查不需要的临时文件。


我已经配置并运行了标准的Magento 2 cron。两天后,在“管理”面板中运行某些操作时遇到了一些问题。当检查服务器日志时,我发现这是磁盘空间问题。经过进一步调查,我发现这update.log.txt是罪魁祸首。文件大小每分钟增加> 1MB。曾经有一段时间它达到了20GB以上。

在此处输入图片说明

标准Magento 2设置正常吗?还是可以&如何禁用它或至少将其最小化?

它同时发生在开发人员模式和生产模式中。

Cron设置基于此指南

Cron标签:

* * * * * <path to php binary> <magento install dir>/bin/magento cron:run | grep -v "Ran jobs by schedule" >> <magento install dir>/var/log/magento.cron.log
* * * * * <path to php binary> <magento install dir>/update/cron.php >> <magento install dir>/var/log/update.cron.log
* * * * * <path to php binary> <magento install dir>/bin/magento setup:cron:run >> <magento install dir>/var/log/setup.cron.log

日志的样本内容

/var/www/html/setup/src/Magento/Setup/Console/Command/I18nCollectPhrasesCommand.php /var/www/html/setup/src/Magento/Setup/Console/Command/MaintenanceStatusCommand.php / var / www / html /setup/src/Magento/Setup/Console/Command/BackupCommand.php /var/www/html/setup/src/Magento/Setup/Console/Command/DependenciesShowFrameworkCommand.php / var / www / html / setup / src / Magento /Setup/Console/Command/UninstallCommand.php /var/www/html/setup/src/Magento/Setup/Console/Command/InfoTimezoneListCommand.php / var / www / html / setup / src / Magento / Setup / Console / Command /MaintenanceAllowIpsCommand.php /var/www/html/setup/src/Magento/Setup/Console/Command/ModuleStatusCommand.php /var/www/html/setup/src/Magento/Setup/Console/Command/InstallStoreConfigurationCommand.php / var / www / html / setup / src / Magento / Setup / Console / Command / InfoBackupsListCommand。php /var/www/html/setup/src/Magento/Setup/Console/Command/MaintenanceDisableCommand.php /var/www/html/setup/src/Magento/Setup/Console/Command/DiCompileCommand.php / var / www / html / setup / src / Magento / Setup / Console / Command / InstallCommand.php /var/www/html/setup/src/Magento/Setup/Console/Command/UpgradeCommand.php / var / www / html / setup / src / Magento /设置/夹具/IndexersStatesApplyFixture.php /var/www/html/setup/src/Magento/Setup/Fixtures/StoresFixture.php /var/www/html/setup/src/Magento/Setup/Fixtures/CategoriesFixture.php / var / www / html / setup / src / Magento / Setup / Fixtures / SimpleProductsFixture.php /var/www/html/setup/src/Magento/Setup/Fixtures/tax_rates.csv / var / www / html / setup / src / Magento / Setup / Validator / var / www / html / setup / src / Magento / Setup / Validator / DbValidator。php /var/www/html/setup/src/Magento/Setup/Validator/IpValidator.php /var/www/html/setup/src/Magento/Setup/Validator/AdminCredentialsValidator.php / var / www / html / setup / index.php / var / www / html / setup / performance-toolkit /var/www/html/setup/performance-toolkit/.htaccess / var / www / html / setup / performance-toolkit / profiles / var / www / html / setup / performance-toolkit / profiles / ce /var/www/html/setup/performance-toolkit/profiles/ce/large.xml /var/www/html/setup/performance-toolkit/profiles/ce/small.xml /var/www/html/setup/performance-toolkit/profiles/ce/medium.xml /var/www/html/setup/performance-toolkit/profiles/ce/extra_large.xml / var / www / html / setup / performance -toolkit / README.txt /var/www/html/setup/performance-toolkit/benchmark.jmx /var/www/html/vendor/.htaccess [] []php /var/www/html/setup/src/Magento/Setup/Validator/AdminCredentialsValidator.php /var/www/html/setup/index.php / var / www / html / setup / performance-toolkit / var / www / html / setup / performance-toolkit / .htaccess / var / www / html / setup / performance-toolkit / profiles / var / www / html / setup / performance-toolkit / profiles / ce / var / www / html / setup / performance -toolkit / profiles / ce / large.xml /var/www/html/setup/performance-toolkit/profiles/ce/small.xml /var/www/html/setup/performance-toolkit/profiles/ce/medium.xml /var/www/html/setup/performance-toolkit/profiles/ce/extra_large.xml /var/www/html/setup/performance-toolkit/README.txt / var / www / html / setup / performance-toolkit / benchmark .jmx /var/www/html/vendor/.htaccess [] []php /var/www/html/setup/src/Magento/Setup/Validator/AdminCredentialsValidator.php /var/www/html/setup/index.php / var / www / html / setup / performance-toolkit / var / www / html / setup / performance-toolkit / .htaccess / var / www / html / setup / performance-toolkit / profiles / var / www / html / setup / performance-toolkit / profiles / ce / var / www / html / setup / performance -toolkit / profiles / ce / large.xml /var/www/html/setup/performance-toolkit/profiles/ce/small.xml /var/www/html/setup/performance-toolkit/profiles/ce/medium.xml /var/www/html/setup/performance-toolkit/profiles/ce/extra_large.xml /var/www/html/setup/performance-toolkit/README.txt / var / www / html / setup / performance-toolkit / benchmark .jmx /var/www/html/vendor/.htaccess [] []php / var / www / html / setup / performance-toolkit /var/www/html/setup/performance-toolkit/.htaccess / var / www / html / setup / performance-toolkit / profiles / var / www / html / setup / performance-toolkit / profiles / ce /var/www/html/setup/performance-toolkit/profiles/ce/large.xml /var/www/html/setup/performance-toolkit/profiles/ce/small.xml / var /www/html/setup/performance-toolkit/profiles/ce/medium.xml /var/www/html/setup/performance-toolkit/profiles/ce/extra_large.xml / var / www / html / setup / performance-toolkit /README.txt /var/www/html/setup/performance-toolkit/benchmark.jmx /var/www/html/vendor/.htaccess [] []php / var / www / html / setup / performance-toolkit /var/www/html/setup/performance-toolkit/.htaccess / var / www / html / setup / performance-toolkit / profiles / var / www / html / setup / performance-toolkit / profiles / ce /var/www/html/setup/performance-toolkit/profiles/ce/large.xml /var/www/html/setup/performance-toolkit/profiles/ce/small.xml / var /www/html/setup/performance-toolkit/profiles/ce/medium.xml /var/www/html/setup/performance-toolkit/profiles/ce/extra_large.xml / var / www / html / setup / performance-toolkit /README.txt /var/www/html/setup/performance-toolkit/benchmark.jmx /var/www/html/vendor/.htaccess [] []htaccess / var / www / html / setup / performance-toolkit / profiles / var / www / html / setup / performance-toolkit / profiles / ce / var / www / html / setup / performance-toolkit / profiles / ce / large。 xml /var/www/html/setup/performance-toolkit/profiles/ce/small.xml /var/www/html/setup/performance-toolkit/profiles/ce/medium.xml / var / www / html / setup / performance-toolkit / profiles / ce / extra_large.xml /var/www/html/setup/performance-toolkit/README.txt /var/www/html/setup/performance-toolkit/benchmark.jmx / var / www / html /供应商/.htaccess [] []htaccess / var / www / html / setup / performance-toolkit / profiles / var / www / html / setup / performance-toolkit / profiles / ce / var / www / html / setup / performance-toolkit / profiles / ce / large。 xml /var/www/html/setup/performance-toolkit/profiles/ce/small.xml /var/www/html/setup/performance-toolkit/profiles/ce/medium.xml / var / www / html / setup / performance-toolkit / profiles / ce / extra_large.xml /var/www/html/setup/performance-toolkit/README.txt /var/www/html/setup/performance-toolkit/benchmark.jmx / var / www / html /供应商/.htaccess [] []txt /var/www/html/setup/performance-toolkit/benchmark.jmx /var/www/html/vendor/.htaccess [] []txt /var/www/html/setup/performance-toolkit/benchmark.jmx /var/www/html/vendor/.htaccess [] []

我发现可能会生成/更新此日志的地方很少:

<INSTALL_DIR>setup\src\Magento\Setup\Console\Command\CronRunCommand.php:
       75      protected function execute(InputInterface $input, OutputInterface $output)
       76      {
       77:         $notification = 'setup-cron: Please check var/log/update.log for execution summary.';
       78  
       79          if (!$this->deploymentConfig->isAvailable()) {

    <INSTALL_DIR>setup\src\Magento\Setup\Model\Cron\ReadinessCheck.php:
      164          $write->writeFile(self::SETUP_CRON_JOB_STATUS_FILE, $resultJson);
      165  
      166:         // write to permanent log file, var/log/update.log
      167          foreach ($errorLogMessages as $errorLog) {
      168              $this->status->add($errorLog, \Psr\Log\LogLevel::ERROR, false);

    <INSTALL_DIR>setup\src\Magento\Setup\Model\Cron\SetupLoggerFactory.php:
       22      {
       23          $logger = new \Monolog\Logger($channelName);
       24:         $path = BP . '/var/log/update.log';
       25          $logger->pushHandler(new \Monolog\Handler\StreamHandler($path));
       26          return $logger;

    <INSTALL_DIR>setup\src\Magento\Setup\Model\Cron\SetupStreamHandler.php:
       17       * @var string
       18       */
       19:     protected $fileName = '/var/log/update.log';
       20  
       21      /**

    <INSTALL_DIR>setup\src\Magento\Setup\Model\Cron\Status.php:
       81          $this->varReaderWriter = $filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
       82          $this->statusFilePath = $statusFilePath ? $statusFilePath : '.update_status.txt';
       83:         $this->logFilePath = $logFilePath ? $logFilePath : DirectoryList::LOG . '/update.log';
       84          $this->updateInProgressFlagFilePath = $updateInProgressFlagFilePath
       85              ? $updateInProgressFlagFilePath

    <INSTALL_DIR>setup\src\Magento\Setup\Test\Unit\Model\Cron\StatusTest.php:
       71          $this->varReaderWriter->expects($this->any())
       72              ->method('getAbsolutePath')
       73:             ->with('log/update.log')
       74:             ->willReturn('DIR/var/log/update.log');
       75:         $this->assertEquals('DIR/var/log/update.log', $this->status->getLogFilePath());
       76      }
       77  

    <INSTALL_DIR>update\app\code\Magento\Update\CronReadinessCheck.php:
       16      const CRON_JOB_STATUS_FILE = '.update_cronjob_status';
       17  
       18:     const UPDATE_CRON_LOG_FILE = 'var/log/update.log';
       19  
       20      /**#@+
       ..
       91          file_put_contents(MAGENTO_BP . '/var/' . self::CRON_JOB_STATUS_FILE, $resultJson);
       92  
       93:         // If non-accessible paths are found, log an 'error' entry for the same in update.log
       94          if ( !$success && !empty($outputString) ) {
       95              $updateLoggerFactory = new UpdateLoggerFactory();

    <INSTALL_DIR>update\app\code\Magento\Update\Status.php:
       67      ) {
       68          $this->statusFilePath = $statusFilePath ? $statusFilePath : MAGENTO_BP . '/var/.update_status.txt';
       69:         $this->logFilePath = $logFilePath ? $logFilePath : MAGENTO_BP . '/var/log/update.log';
       70          $this->updateInProgressFlagFilePath = $updateInProgressFlagFilePath
       71              ? $updateInProgressFlagFilePath

    <INSTALL_DIR>update\app\code\Magento\Update\UpdateLoggerFactory.php:
       29       */
       30      public function __construct(
       31:         $logFile = '/var/log/update.log',
       32          $channelName = 'update-cron'
       33      ) {

    <INSTALL_DIR>update\cron.php:
       15  $status = new \Magento\Update\Status();
       16  $cronReadinessChecker = new \Magento\Update\CronReadinessCheck();
       17: $notification = 'update-cron: Please check var/log/update.log for execution summary.' . PHP_EOL;
       18  
       19  if (!$cronReadinessChecker->runReadinessCheck()) {

    <INSTALL_DIR>update\dev\tests\integration\testsuite\Magento\Update\StatusTest.php:
       43          $this->statusFilePath = __DIR__ . '/_files/update_status.txt';
       44          $this->tmpStatusFilePath = TESTS_TEMP_DIR . '/update_status.txt';
       45:         $this->tmpStatusLogFilePath = TESTS_TEMP_DIR . '/update.log';
       46          $this->updateInProgressFlagFilePath = TESTS_TEMP_DIR . '/update_in_progress.flag';
       47          $this->updateErrorFlagFilePath = TESTS_TEMP_DIR . '/update_error.flag';

更新:

我最终使用logrotate实用程序来处理不断增长的日志文件。我还设置了一些cron作业,这些作业将不时检查不需要的临时文件。


1
我的商店遇到同样的问题。我的update.log文件是23g,实际上昨晚使我的mysql崩溃了。我不确定发生了什么-我安装了相当普通的软件。
Budget Woodworker '02

Answers:


6

据我所知,该var/log/update.log文件确实与cron一起使用。

声明在 \setup\src\Magento\Setup\Model\Cron\Status.php

$this->logFilePath = $logFilePath ? $logFilePath : DirectoryList::LOG . '/update.log';

然后通过该getLogFilePath()方法进行检索。

如果检查此方法的调用位置,则位于\setup\src\Magento\Setup\Model\Cron\JobFactory.php

$logStream = fopen($cronStatus->getLogFilePath(), 'a+');
$streamOutput = new MultipleStreamOutput([$statusStream, $logStream]);

然后将该$streamOutput变量作为参数传递给作业类,例如:

return new JobUpgrade(
    $this->serviceLocator->get('Magento\Setup\Console\Command\UpgradeCommand'),
    $objectManagerProvider,
    $streamOutput,
    $this->serviceLocator->get('Magento\Setup\Model\Cron\Queue'),
    $cronStatus,
    $name,
    $params
);

如果继续讲这个示例,$this->output则在execute()方法中使用:

$this->command->run(new ArrayInput($this->params), $this->output);

run()方法在中声明vendor\symfony\console\Symfony\Component\Console\Command\Command.php

$output然后在多个地方使用该变量,例如:

    $this->initialize($input, $output);

以及 :

    if ($input->isInteractive()) {
        $this->interact($input, $output);
    }

    $input->validate();

    if ($this->code) {
        $statusCode = call_user_func($this->code, $input, $output);
    } else {
        $statusCode = $this->execute($input, $output);
    }

另一个有趣的是:

        } elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
            $output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
        }

根据最后的代码,在参数非常冗长的情况下可以编写一些东西。也许您使用设置了cron作业,-vv这就是为什么东西被记录的原因。

这不是一个确定的答案,但是您应该遵循我刚刚给您提供的堆栈跟踪来调查问题。


2

您可能在某些文件夹上设置了错误的权限。/ update / cron列出所有具有错误权限的文件夹

简单的方法就是在crontab更新和设置中注释掉

#* * * * * <path to php binary> <magento install dir>/update/cron.php >> <magento install dir>/var/log/update.cron.log
#* * * * * <path to php binary> <magento install dir>/bin/magento setup:cron:run >> <magento install dir>/var/log/setup.cron.log

如果不需要从管理面板更新和安装,则不需要它们。

对于生产服务器来说,这是一个危险的主意。您可以通过测试/本地服务器上的composer手动更新;测试;然后将更新复制到生产服务器。

您真正需要的是

* * * * * <path to php binary> <magento install dir>/bin/magento cron:run | grep -v "Ran jobs by schedule" >> <magento install dir>/var/log/magento.cron.log

它管理“索引器,发送自动电子邮件,生成站点地图等”-如devdocs中所述


是的,这在Magento 2文档中也已说明,用于配置cron。无论如何,我们最终使用logrotate和一些自定义cron作业来检查和清理文件系统,目的是优化磁盘空间使用。
reuelab


0

据我所知update.log是您的自定义日志文件,因为Magento 2会生成此类文件

  • var / log / debug.log –由Psr \ Log \ LoggerInterface :: debug()保存的所有信息都存储在此处。
  • var / log / exception.log –所有异常信息都存储在此处。
  • var / log / system.log-其他日志记录级别的信息保存在此处。

我不确定为什么它会在文件中生成大量日志数据,可能是语法错误或类似的错误。

但是我建议您只update.log在您的Magento 2代码目录中使用with进行搜索,然后从您的代码中删除该日志。


嗨,谢谢您的回答。我不认为这是一个自定义日志,因为我可以在一些默认的Magento类上找到它。我已经更新了我的问题,以获取更多信息。
reuelab '17
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.