Skip to content

Commit 7a254ac

Browse files
config-dev-view: Allow user to download system logs
1 parent 615e7e9 commit 7a254ac

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/views/ConfigurationDevelopmentView.vue

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,52 @@
1313
step="1"
1414
thumb-label="always"
1515
/>
16+
<v-data-table :items="systemLogsData" :headers="headers" class="max-w-[80%] max-h-[60%]">
17+
<template #item.actions="{ item }">
18+
<div class="text-center cursor-pointer icon-btn mdi mdi-download" @click="downloadLog(item.name)" />
19+
</template>
20+
</v-data-table>
1621
</template>
1722
</BaseConfigurationView>
1823
</template>
1924

2025
<script setup lang="ts">
26+
import { saveAs } from 'file-saver'
27+
import { onBeforeMount } from 'vue'
28+
import { ref } from 'vue'
29+
30+
import { type SystemLog, cockpitSytemLogsDB } from '@/libs/system-logging'
2131
import { useDevelopmentStore } from '@/stores/development'
2232
2333
import BaseConfigurationView from './BaseConfigurationView.vue'
24-
2534
const devStore = useDevelopmentStore()
35+
36+
const systemLogsData = ref<Record<string, string | number>[]>([])
37+
38+
const headers = [
39+
{ title: 'Name', value: 'name' },
40+
{ title: 'Time (initial)', value: 'initialTime' },
41+
{ title: 'Date (initial)', value: 'initialDate' },
42+
{ title: 'N. events', value: 'nEvents' },
43+
{ title: 'Actions', value: 'actions' },
44+
]
45+
46+
onBeforeMount(async () => {
47+
await cockpitSytemLogsDB.iterate((log: SystemLog, logName) => {
48+
systemLogsData.value.push({
49+
name: logName,
50+
initialTime: log.initialTime,
51+
initialDate: log.initialDate,
52+
nEvents: log.events.length,
53+
})
54+
})
55+
console.log(systemLogsData.value)
56+
})
57+
58+
const downloadLog = async (logName: string): Promise<void> => {
59+
const log = await cockpitSytemLogsDB.getItem(logName)
60+
const logParts = JSON.stringify(log, null, 2)
61+
const logBlob = new Blob([logParts], { type: 'application/json' })
62+
saveAs(logBlob, logName)
63+
}
2664
</script>

0 commit comments

Comments
 (0)