HEX
Server: LiteSpeed
System: Linux d8 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
User: wbwebdes (3015)
PHP: 8.1.31
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: /home/wbwebdes/domains/files.wb-cloud.nl/public_html/apps/logreader/lib/Service/SettingsService.php
<?php

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

namespace OCA\LogReader\Service;

use OCA\LogReader\Constants;
use OCP\IConfig;

class SettingsService {
	public function __construct(
		private IConfig $config,
	) {
		$this->config = $config;
	}

	/**
	 * Load shown levels from app config
	 */
	public function getShownLevels(): array {
		return json_decode($this->config->getAppValue('logreader', Constants::CONFIG_KEY_SHOWNLEVELS, '[0,1,2,3,4]'), flags: JSON_THROW_ON_ERROR);
	}

	/**
	 * Load date time format to use for user from app config
	 */
	public function getDateTimeFormat(): string {
		return json_decode($this->config->getAppValue('logreader', Constants::CONFIG_KEY_DATETIMEFORMAT, '"local"'), flags: JSON_THROW_ON_ERROR);
	}

	/**
	 * Load app config if dates should be displayed as relative dates
	 */
	public function getRelativeDates(): bool {
		return json_decode($this->config->getAppValue('logreader', Constants::CONFIG_KEY_RELATIVEDATES, 'false') ?: 'false', flags: JSON_THROW_ON_ERROR);
	}

	/**
	 * Load app config if log should be updated automatically
	 */
	public function getLiveLog(): bool {
		return json_decode($this->config->getAppValue('logreader', Constants::CONFIG_KEY_LIVELOG, 'true'), flags: JSON_THROW_ON_ERROR);
	}

	/**
	 * Get all app settings for displaying the logfiles
	 */
	public function getAppSettings(): array {
		return [
			Constants::CONFIG_KEY_SHOWNLEVELS => $this->getShownLevels(),
			Constants::CONFIG_KEY_LOGLEVEL => $this->config->getSystemValueInt('loglevel', 2),
			Constants::CONFIG_KEY_DATETIMEFORMAT => $this->getDateTimeFormat(),
			Constants::CONFIG_KEY_RELATIVEDATES => $this->getRelativeDates(),
			Constants::CONFIG_KEY_LIVELOG => $this->getLiveLog(),
			'enabled' => $this->getLoggingType() === 'file',
		];
	}

	/**
	 * Get system setting of the logging type
	 */
	public function getLoggingType(): string {
		return $this->config->getSystemValueString('log_type', 'file');
	}

	/**
	 * Get system setting of the log file name
	 */
	public function getLoggingFile(): string {
		return $this->config->getSystemValueString('logile', '');
	}

	/**
	 * Get system setting for the log date format
	 */
	public function getLoggingDateFormat(): string {
		// see default: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/logging_configuration.html#file
		return $this->config->getSystemValueString('logdateformat', 'c');
	}

	/**
	 * Get system setting for the log timezone
	 */
	public function getLoggingTimezone(): string {
		return $this->config->getSystemValueString('logtimezone', 'UTC');
	}
}