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
4 changes: 2 additions & 2 deletions css/logreader-main.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions js/Splitter-7c596d5a.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*! third party licenses: js/vendor.LICENSE.txt */
import{g as d}from"./logreader-main.mjs";function h(r,c){for(var s=0;s<c.length;s++){const t=c[s];if(typeof t!="string"&&!Array.isArray(t)){for(const a in t)if(a!=="default"&&!(a in r)){const e=Object.getOwnPropertyDescriptor(t,a);e&&Object.defineProperty(r,a,e.get?e:{enumerable:!0,get:()=>t[a]})}}}return Object.freeze(Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}))}var g=function(r){for(var c=0,s=1,t=2,a=3,e=c,i=0,b=null,o=[],n=0;n<r.length;++n)switch(e){case c:switch(r[n]){case"{":++i,e=s,b=n;break}break;case s:switch(r[n]){case"{":++i;break;case"}":--i,i===0&&(e=c,o.push({start:b,end:n+1}));break;case'"':e=t;break}break;case t:switch(r[n]){case'"':e=s;break;case"\\":e=a;break}break;case a:e=t;break}var f={jsons:[],remainder:r.substring(o[o.length-1].end)};return o.forEach(function(u){f.jsons.push(r.substring(u.start,u.end))}),f};const k=d(g),p=h({__proto__:null,default:k},[g]);export{p as S};

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions js/Splitter-9140b094.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion js/logreader-main.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/logreader-main.mjs.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ class Constants {
* Used AppConfig Keys
*/
public const CONFIG_KEY_SHOWNLEVELS = 'shownLevels';
public const CONFIG_KEY_LOGLEVEL = 'logLevel';
public const CONFIG_KEY_DATETIMEFORMAT = 'dateTimeFormat';
public const CONFIG_KEY_RELATIVEDATES = 'relativedates';
public const CONFIG_KEY_LIVELOG = 'liveLog';
public const CONFIG_KEYS = [
self::CONFIG_KEY_SHOWNLEVELS,
self::CONFIG_KEY_LOGLEVEL,
self::CONFIG_KEY_DATETIMEFORMAT,
self::CONFIG_KEY_RELATIVEDATES,
self::CONFIG_KEY_LIVELOG
Expand Down
14 changes: 12 additions & 2 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,18 @@ public function updateAppConfig(string $settingsKey, $settingsValue): JSONRespon
}
}

// Set on DB
$this->config->setAppValue($this->appName, $settingsKey, json_encode($settingsValue));
if ($settingsKey === Constants::CONFIG_KEY_LOGLEVEL) {
// Validate loglevel value
if (!is_int($settingsValue) || $settingsValue < 0 || $settingsValue > 4) {
$this->logger->debug('Cannot set {settingsValue} as loglevel', ['settingsValue' => $settingsValue ]);
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
}
// Set backend loglevel directly via system value
$this->config->setSystemValue('loglevel', $settingsValue);
} else {
// Set on DB
$this->config->setAppValue($this->appName, $settingsKey, json_encode($settingsValue));
}

return new JSONResponse();
}
Expand Down
1 change: 1 addition & 0 deletions lib/Service/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function getLiveLog(): bool {
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(),
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/components/settings/AppSettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<NcAppSettingsSection id="logreader-settings-levels" :name="t('logreader', 'Filter log levels')">
<SettingsLogLevels />
</NcAppSettingsSection>
<NcAppSettingsSection id="logreader-settings-set-level" :name="t('logreader', 'Set log level')">
<SettingsSetLogLevel />
</NcAppSettingsSection>
<NcAppSettingsSection id="logreader-settings-time" :name="t('logreader', 'Time format')">
<SettingsDatetimeFormat />
</NcAppSettingsSection>
Expand All @@ -27,6 +30,7 @@ import { translate as t } from '@nextcloud/l10n'
import SettingsActions from './SettingsActions.vue'
import SettingsLiveView from './SettingsLiveView.vue'
import SettingsLogLevels from './SettingsLogLevels.vue'
import SettingsSetLogLevel from './SettingsSetLogLevel.vue'
import SettingsDatetimeFormat from './SettingsDatetimeFormat.vue'

import NcAppSettingsDialog from '@nextcloud/vue/dist/Components/NcAppSettingsDialog.js'
Expand Down
49 changes: 49 additions & 0 deletions src/components/settings/SettingsSetLogLevel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<fieldset>
<legend>{{ t('logreader', 'Set backend loglevel') }}</legend>
<NcCheckboxRadioSwitch v-for="levelName, levelId in LOGGING_LEVEL_NAMES"
:key="levelId"
:checked="logLevel"
:value="`${levelId}`"
type="radio"
name="loglevel"
@update:checked="setLogLevel">
{{ levelName }}
</NcCheckboxRadioSwitch>
</fieldset>
</template>

<script setup lang="ts">
import type { IAppSettings } from '../../interfaces'

import { computed } from 'vue'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { useSettingsStore } from '../../store/settings'
import { logger } from '../../utils/logger'
import { LOGGING_LEVEL_NAMES } from '../../constants'

import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'

const settingsStore = useSettingsStore()

/**
* Get currently set loglevel
*/
const logLevel = computed(() => `${settingsStore.logLevel}`)

const setLogLevel = (level: string) => {
const numericLevel = parseInt(level) as IAppSettings['logLevel']
settingsStore.setSetting('logLevel', numericLevel)
.catch(e => {
showError(t('logreader', 'Could not set logging level'))
logger.error(e as Error)
})
}
</script>

<style scoped>
fieldset {
padding: 6px;
}
</style>
4 changes: 4 additions & 0 deletions src/interfaces/IAppSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ export interface IAppSettings {
* Wether backend is enable = logging is set to file
*/
enabled: boolean
/**
* The loglevel which is currently set on the server
*/
logLevel: 0 | 1 | 2 | 3 | 4
}
9 changes: 7 additions & 2 deletions src/store/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useSettingsStore = defineStore('logreader-settings', () => {
/**
* Saved setting loaded from server
*/
const _loadedSettings = loadState<SettingsState>('logreader', 'settings', { enabled: false, liveLog: false, dateTimeFormat: 'raw', shownLevels: [] })
const _loadedSettings = loadState<SettingsState>('logreader', 'settings', { enabled: false, liveLog: false, dateTimeFormat: 'raw', shownLevels: [], logLevel: 2 })

/**
* Is file logging enabled on server
Expand All @@ -47,6 +47,11 @@ export const useSettingsStore = defineStore('logreader-settings', () => {
*/
const shownLevels = ref(_loadedSettings.shownLevels)

/**
* The current log level set on the server
*/
const logLevel = ref(_loadedSettings.logLevel)

/**
* The datetime format to used for displaying times
* This is the internal property used for the computed getter
Expand Down Expand Up @@ -102,5 +107,5 @@ export const useSettingsStore = defineStore('logreader-settings', () => {
return settings.data
}

return { shownLevels, dateTimeFormat, enabled, isEnabled, liveLog, localFile, localFileName, setSetting, getSettings }
return { shownLevels, logLevel, dateTimeFormat, enabled, isEnabled, liveLog, localFile, localFileName, setSetting, getSettings }
})
28 changes: 27 additions & 1 deletion tests/Unit/Controller/SettingsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SettingsControllerTest extends TestCase {
/** @var SettingsController */
private $settingsController;

/** @var SettingsService */
/** @var SettingsService|MockObject */
private $settingsService;

/** @var IConfig|MockObject */
Expand All @@ -59,6 +59,7 @@ public function setUp(): void {

$this->settingsService = $this->createMock(SettingsService::class);
$this->config = $this->createMock(IConfig::class);
/** @var LoggerInterface */
$this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$this->request = $this->createMock(IRequest::class);

Expand All @@ -76,6 +77,7 @@ public function testGetAppConfig() {
->method('getAppSettings')
->willReturn([
Constants::CONFIG_KEY_SHOWNLEVELS => Constants::LOGGING_LEVELS,
Constants::CONFIG_KEY_LOGLEVEL => 4,
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
Constants::CONFIG_KEY_RELATIVEDATES => false,
Constants::CONFIG_KEY_LIVELOG => true,
Expand All @@ -84,6 +86,7 @@ public function testGetAppConfig() {

$this->assertEquals(new JSONResponse([
Constants::CONFIG_KEY_SHOWNLEVELS => Constants::LOGGING_LEVELS,
Constants::CONFIG_KEY_LOGLEVEL => 4,
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
Constants::CONFIG_KEY_RELATIVEDATES => false,
Constants::CONFIG_KEY_LIVELOG => true,
Expand Down Expand Up @@ -124,6 +127,7 @@ public function testUpdateAppConfig(string $configKey, $configValue, string $str
->method('getAppSettings')
->willReturn([
Constants::CONFIG_KEY_SHOWNLEVELS => Constants::LOGGING_LEVELS,
Constants::CONFIG_KEY_LOGLEVEL => 3,
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
Constants::CONFIG_KEY_RELATIVEDATES => false,
Constants::CONFIG_KEY_LIVELOG => true,
Expand All @@ -133,6 +137,28 @@ public function testUpdateAppConfig(string $configKey, $configValue, string $str
$this->assertEquals(new JSONResponse(), $this->settingsController->updateAppConfig($configKey, $configValue));
}

public function testUpdateAppConfig_logLevel() {
$this->logger->expects($this->once())
->method('debug');

$this->config->expects($this->once())
->method('setSystemValue')
->with('loglevel', 4);

$this->settingsService->expects($this->once())
->method('getAppSettings')
->willReturn([
Constants::CONFIG_KEY_SHOWNLEVELS => Constants::LOGGING_LEVELS,
Constants::CONFIG_KEY_LOGLEVEL => 3,
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
Constants::CONFIG_KEY_RELATIVEDATES => false,
Constants::CONFIG_KEY_LIVELOG => true,
'enabled' => true,
]);

$this->assertEquals(new JSONResponse(), $this->settingsController->updateAppConfig(Constants::CONFIG_KEY_LOGLEVEL, 4));
}

public function testUpdateAppConfig_unknownKey() {
$this->logger->expects($this->any())
->method('debug');
Expand Down
14 changes: 12 additions & 2 deletions tests/Unit/Service/SettingsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
use OCA\LogReader\Constants;
use OCA\LogReader\Service\SettingsService;
use OCP\IConfig;

use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class SettingsServiceTest extends TestCase {

/** @var SettingsService */
private $settingsService;

/** @var IConfig */
/** @var IConfig|MockObject */
private $config;

public function setUp(): void {
Expand Down Expand Up @@ -134,6 +134,10 @@ public function testGetAppSettings() {
->method('getSystemValueString')
->with($this->equalTo('log_type'), $this->anything())
->willReturn('file');
$this->config->expects($this->once())
->method('getSystemValueInt')
->with($this->equalTo('loglevel'), 2)
->willReturn(4);
$this->config->expects($this->any())
->method('getAppValue')
->willReturnCallback(function ($app, $key, $fallback) {
Expand All @@ -142,6 +146,7 @@ public function testGetAppSettings() {

$this->assertEquals($this->settingsService->getAppSettings(), [
Constants::CONFIG_KEY_SHOWNLEVELS => Constants::LOGGING_LEVELS,
Constants::CONFIG_KEY_LOGLEVEL => 4,
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
Constants::CONFIG_KEY_RELATIVEDATES => false,
Constants::CONFIG_KEY_LIVELOG => true,
Expand All @@ -154,6 +159,10 @@ public function testGetAppSettings_nonfile() {
->method('getSystemValueString')
->with($this->equalTo('log_type'), $this->anything())
->willReturn('syslog');
$this->config->expects($this->once())
->method('getSystemValueInt')
->with($this->equalTo('loglevel'), 2)
->willReturn(2);
$this->config->expects($this->any())
->method('getAppValue')
->willReturnCallback(function ($app, $key, $fallback) {
Expand All @@ -162,6 +171,7 @@ public function testGetAppSettings_nonfile() {

$this->assertEquals($this->settingsService->getAppSettings(), [
Constants::CONFIG_KEY_SHOWNLEVELS => Constants::LOGGING_LEVELS,
Constants::CONFIG_KEY_LOGLEVEL => 2,
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
Constants::CONFIG_KEY_RELATIVEDATES => false,
Constants::CONFIG_KEY_LIVELOG => true,
Expand Down