Skip to content

Commit 90cf2ed

Browse files
committed
Feature: set log level via settings UI
Signed-off-by: Robin Windey <[email protected]>
1 parent c34b5fc commit 90cf2ed

File tree

12 files changed

+126
-10
lines changed

12 files changed

+126
-10
lines changed

css/logreader-index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/logreader-main.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

js/logreader-main.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Constants.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ class Constants {
3232
* Used AppConfig Keys
3333
*/
3434
public const CONFIG_KEY_SHOWNLEVELS = 'shownLevels';
35+
public const CONFIG_KEY_LOGLEVEL = 'logLevel';
3536
public const CONFIG_KEY_DATETIMEFORMAT = 'dateTimeFormat';
3637
public const CONFIG_KEY_RELATIVEDATES = 'relativedates';
3738
public const CONFIG_KEY_LIVELOG = 'liveLog';
3839
public const CONFIG_KEYS = [
3940
self::CONFIG_KEY_SHOWNLEVELS,
41+
self::CONFIG_KEY_LOGLEVEL,
4042
self::CONFIG_KEY_DATETIMEFORMAT,
4143
self::CONFIG_KEY_RELATIVEDATES,
4244
self::CONFIG_KEY_LIVELOG

lib/Controller/SettingsController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ public function updateAppConfig(string $settingsKey, $settingsValue): JSONRespon
9292
}
9393
}
9494

95-
// Set on DB
96-
$this->config->setAppValue($this->appName, $settingsKey, json_encode($settingsValue));
95+
if ($settingsKey === Constants::CONFIG_KEY_LOGLEVEL) {
96+
// Set backend loglevel directly via system value
97+
$this->config->setSystemValue('loglevel', $settingsValue);
98+
} else {
99+
// Set on DB
100+
$this->config->setAppValue($this->appName, $settingsKey, json_encode($settingsValue));
101+
}
97102

98103
return new JSONResponse();
99104
}

lib/Service/SettingsService.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function getLiveLog(): bool {
6565
public function getAppSettings(): array {
6666
return [
6767
Constants::CONFIG_KEY_SHOWNLEVELS => $this->getShownLevels(),
68+
Constants::CONFIG_KEY_LOGLEVEL => $this->config->getSystemValueInt('loglevel', 0),
6869
Constants::CONFIG_KEY_DATETIMEFORMAT => $this->getDateTimeFormat(),
6970
Constants::CONFIG_KEY_RELATIVEDATES => $this->getRelativeDates(),
7071
Constants::CONFIG_KEY_LIVELOG => $this->getLiveLog(),

src/components/settings/AppSettingsDialog.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<NcAppSettingsSection id="logreader-settings-levels" :name="t('logreader', 'Filter log levels')">
1111
<SettingsLogLevels />
1212
</NcAppSettingsSection>
13+
<NcAppSettingsSection id="logreader-settings-set-level" :name="t('logreader', 'Set log level')">
14+
<SettingsSetLogLevel />
15+
</NcAppSettingsSection>
1316
<NcAppSettingsSection id="logreader-settings-time" :name="t('logreader', 'Time format')">
1417
<SettingsDatetimeFormat />
1518
</NcAppSettingsSection>
@@ -27,6 +30,7 @@ import { translate as t } from '@nextcloud/l10n'
2730
import SettingsActions from './SettingsActions.vue'
2831
import SettingsLiveView from './SettingsLiveView.vue'
2932
import SettingsLogLevels from './SettingsLogLevels.vue'
33+
import SettingsSetLogLevel from './SettingsSetLogLevel.vue'
3034
import SettingsDatetimeFormat from './SettingsDatetimeFormat.vue'
3135
3236
import NcAppSettingsDialog from '@nextcloud/vue/dist/Components/NcAppSettingsDialog.js'
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<template>
2+
<div>
3+
<fieldset>
4+
<legend>{{ t('logreader', 'Set backend loglevel') }}</legend>
5+
<NcCheckboxRadioSwitch v-for="levelName, levelId in LOGGING_LEVEL_NAMES"
6+
:checked="logLevel"
7+
:value="`${levelId}`"
8+
type="radio"
9+
name="loglevel"
10+
@update:checked="setLogLevel">
11+
{{ levelName }}
12+
</NcCheckboxRadioSwitch>
13+
</fieldset>
14+
</div>
15+
</template>
16+
17+
<script setup lang="ts">
18+
import type { IAppSettings } from '../../interfaces'
19+
20+
import { computed } from 'vue'
21+
import { showError } from '@nextcloud/dialogs'
22+
import { translate as t } from '@nextcloud/l10n'
23+
import { debounce } from '../../utils/debounce'
24+
import { useSettingsStore } from '../../store/settings'
25+
import { LOGGING_LEVEL_NAMES } from '../../constants'
26+
27+
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
28+
29+
const settingsStore = useSettingsStore()
30+
31+
/**
32+
* Get currently set loglevel
33+
*/
34+
const logLevel = computed(() => `${settingsStore.logLevel}`)
35+
36+
// /**
37+
// * Get shown logging levels (to allow filter levels)
38+
// */
39+
// const shownLevels = computed(() => settingsStore.shownLevels.map(l => `${l}`))
40+
41+
// const setShowLevels = debounce((levels: string[]) => {
42+
// const numericLevels = levels.map(level => parseInt(level)) as IAppSettings['shownLevels']
43+
44+
// settingsStore.setSetting('shownLevels', numericLevels)
45+
// .catch(() => showError(t('logreader', 'Could not set logging levels to show')))
46+
// }, 200)
47+
48+
const setLogLevel = (level: string) => {
49+
const numericLevel = parseInt(level) as IAppSettings['logLevel']
50+
settingsStore.setSetting('logLevel', numericLevel)
51+
.catch(() => showError(t('logreader', 'Could not set logging level')))
52+
}
53+
</script>
54+
55+
<style scoped>
56+
fieldset {
57+
padding: 6px;
58+
}
59+
</style>

src/interfaces/IAppSettings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@ export interface IAppSettings {
2727
* Wether backend is enable = logging is set to file
2828
*/
2929
enabled: boolean
30+
/**
31+
* The loglevel which is currently set on the server
32+
*/
33+
logLevel: 0 | 1 | 2 | 3 | 4
3034
}

src/store/settings.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const useSettingsStore = defineStore('logreader-settings', () => {
2424
/**
2525
* Saved setting loaded from server
2626
*/
27-
const _loadedSettings = loadState<SettingsState>('logreader', 'settings', { enabled: false, liveLog: false, dateTimeFormat: 'raw', shownLevels: [] })
27+
const _loadedSettings = loadState<SettingsState>('logreader', 'settings', { enabled: false, liveLog: false, dateTimeFormat: 'raw', shownLevels: [], logLevel: 0 })
2828

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

50+
/**
51+
* The current log level set on the server
52+
*/
53+
const logLevel = ref(_loadedSettings.logLevel)
54+
5055
/**
5156
* The datetime format to used for displaying times
5257
* This is the internal property used for the computed getter
@@ -102,5 +107,5 @@ export const useSettingsStore = defineStore('logreader-settings', () => {
102107
return settings.data
103108
}
104109

105-
return { shownLevels, dateTimeFormat, enabled, isEnabled, liveLog, localFile, localFileName, setSetting, getSettings }
110+
return { shownLevels, logLevel, dateTimeFormat, enabled, isEnabled, liveLog, localFile, localFileName, setSetting, getSettings }
106111
})

0 commit comments

Comments
 (0)