l10n->t('Errors in the log'); } public function getCategory(): string { return 'system'; } public function run(): SetupResult { try { $logIterator = $this->logIteratorFactory->getLogIterator([self::LEVEL_WARNING,self::LEVEL_ERROR,self::LEVEL_FATAL]); } catch (\Exception $e) { if ($e instanceof UnsupportedLogTypeException) { return SetupResult::info($e->getMessage()); } return SetupResult::error( $this->l10n->t('Failed to get an iterator for log entries: %s', [$e->getMessage()]) ); } $count = [ self::LEVEL_WARNING => 0, self::LEVEL_ERROR => 0, self::LEVEL_FATAL => 0, ]; $limit = new \DateTime('7 days ago'); $startTime = microtime(true); foreach ($logIterator as $logItem) { if (!isset($logItem['time'])) { continue; } $time = \DateTime::createFromFormat(\DateTime::ATOM, $logItem['time']); if ($time < $limit) { break; } $count[$logItem['level']]++; if (microtime(true) > $startTime + 5) { $limit = $time; break; } } if (array_sum($count) === 0) { return SetupResult::success($this->l10n->t('No errors in the logs since %s', $this->dateFormatter->formatDateTime($limit))); } elseif ($count[self::LEVEL_ERROR] + $count[self::LEVEL_FATAL] > 0) { return SetupResult::warning( $this->l10n->n( '%n error in the logs since %s', '%n errors in the logs since %s', $count[self::LEVEL_ERROR] + $count[self::LEVEL_FATAL], [$this->dateFormatter->formatDateTime($limit)], ) ); } else { return SetupResult::info( $this->l10n->n( '%n warning in the logs since %s', '%n warnings in the logs since %s', $count[self::LEVEL_WARNING], [$this->dateFormatter->formatDateTime($limit)], ) ); } } }