Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/Exception/UnsupportedLogTypeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\LogReader\Exception;

class UnsupportedLogTypeException extends \Exception {
public function __construct() {
parent::__construct('Logreader application only supports "file" log_type');
}
}
3 changes: 2 additions & 1 deletion lib/Log/LogIteratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace OCA\LogReader\Log;

use OCA\LogReader\Exception\UnsupportedLogTypeException;
use OCP\IConfig;
use OCP\Log\IFileBased;
use OCP\Log\ILogFactory;
Expand All @@ -29,7 +30,7 @@ public function getLogIterator(array $levels): \Iterator {
$timezone = $this->config->getSystemValue('logtimezone', 'UTC');
$logType = $this->config->getSystemValue('log_type', 'file');
if ($logType !== 'file') {
throw new \Exception('Logreader application only supports "file" log_type');
throw new UnsupportedLogTypeException();
}
$log = $this->logFactory->get('file');
if ($log instanceof IFileBased) {
Expand Down
5 changes: 5 additions & 0 deletions lib/SetupChecks/LogErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
namespace OCA\LogReader\SetupChecks;

use OCA\LogReader\Exception\UnsupportedLogTypeException;
use OCA\LogReader\Log\LogIteratorFactory;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
Expand Down Expand Up @@ -40,6 +41,10 @@ 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()])
);
Expand Down
Loading