2021-10-01 01:52:32 +02:00
|
|
|
<template>
|
2022-06-19 10:46:42 +02:00
|
|
|
<div class="w-full h-full">
|
|
|
|
<div class="bg-bg rounded-md shadow-lg border border-white border-opacity-5 p-4 mb-8">
|
|
|
|
<div class="flex items-center mb-2">
|
|
|
|
<h1 class="text-xl">Logs</h1>
|
|
|
|
</div>
|
|
|
|
<div class="flex justify-between mb-2 place-items-end">
|
|
|
|
<ui-text-input ref="input" v-model="search" placeholder="Search filter.." @input="inputUpdate" clearable class="w-full sm:w-40 h-8 text-sm sm:mb-0" />
|
2021-10-01 01:52:32 +02:00
|
|
|
|
2022-06-19 10:46:42 +02:00
|
|
|
<ui-dropdown v-model="newServerSettings.logLevel" label="Server Log Level" :items="logLevelItems" @input="logLevelUpdated" class="w-full sm:w-44" />
|
2021-10-01 01:52:32 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="relative">
|
2022-06-19 10:53:23 +02:00
|
|
|
<div ref="container" class="relative w-full h-full bg-primary border-bg overflow-x-hidden overflow-y-auto text-red shadow-inner rounded-md" style="max-height: 800px; min-height: 550px">
|
2021-10-01 01:52:32 +02:00
|
|
|
<template v-for="(log, index) in logs">
|
|
|
|
<div :key="index" class="flex flex-nowrap px-2 py-1 items-start text-sm bg-opacity-10" :class="`bg-${logColors[log.level]}`">
|
2022-06-18 18:34:28 +02:00
|
|
|
<p class="text-gray-400 w-36 font-mono text-xs">{{ log.timestamp }}</p>
|
|
|
|
<p class="font-semibold w-12 text-right text-sm" :class="`text-${logColors[log.level]}`">{{ log.levelName }}</p>
|
2021-10-01 01:52:32 +02:00
|
|
|
<p class="px-4 logmessage">{{ log.message }}</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div v-if="!logs.length" class="absolute top-0 left-0 w-full h-full flex flex-col items-center justify-center text-center">
|
|
|
|
<p class="text-xl text-gray-200 mb-2">No Logs</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
2021-11-01 01:10:45 +01:00
|
|
|
search: null,
|
|
|
|
searchTimeout: null,
|
|
|
|
searchText: null,
|
2021-10-01 01:52:32 +02:00
|
|
|
newServerSettings: {},
|
|
|
|
logColors: ['yellow-200', 'gray-400', 'info', 'warning', 'error', 'red-800', 'blue-400'],
|
|
|
|
logLevels: [
|
|
|
|
{
|
|
|
|
value: 1,
|
|
|
|
text: 'Debug'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 2,
|
|
|
|
text: 'Info'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: 3,
|
|
|
|
text: 'Warn'
|
|
|
|
}
|
2021-11-01 01:10:45 +01:00
|
|
|
],
|
|
|
|
loadedLogs: []
|
2021-10-01 01:52:32 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
serverSettings(newVal, oldVal) {
|
|
|
|
if (newVal && !oldVal) {
|
|
|
|
this.newServerSettings = { ...this.serverSettings }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
logs() {
|
|
|
|
this.updateScroll()
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
logLevelItems() {
|
|
|
|
if (process.env.NODE_ENV === 'production') return this.logLevels
|
|
|
|
this.logLevels.unshift({ text: 'Trace', value: 0 })
|
|
|
|
return this.logLevels
|
|
|
|
},
|
|
|
|
logs() {
|
2021-11-01 01:10:45 +01:00
|
|
|
return this.loadedLogs.filter((log) => {
|
|
|
|
if (log.level >= this.newServerSettings.logLevel) {
|
|
|
|
if (this.searchText) {
|
|
|
|
return log.message.toLowerCase().includes(this.searchText)
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
2021-10-01 01:52:32 +02:00
|
|
|
})
|
|
|
|
},
|
|
|
|
serverSettings() {
|
|
|
|
return this.$store.state.serverSettings
|
|
|
|
},
|
2022-03-14 01:34:31 +01:00
|
|
|
streamLibraryItem() {
|
|
|
|
return this.$store.state.streamLibraryItem
|
2021-10-01 01:52:32 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2021-11-01 01:10:45 +01:00
|
|
|
inputUpdate() {
|
|
|
|
clearTimeout(this.searchTimeout)
|
|
|
|
this.searchTimeout = setTimeout(() => {
|
|
|
|
if (!this.search || !this.search.trim()) {
|
|
|
|
this.searchText = ''
|
|
|
|
return
|
|
|
|
}
|
|
|
|
this.searchText = this.search.toLowerCase().trim()
|
|
|
|
}, 500)
|
|
|
|
},
|
2021-10-01 01:52:32 +02:00
|
|
|
updateScroll() {
|
|
|
|
if (this.$refs.container) {
|
|
|
|
this.$refs.container.scrollTop = this.$refs.container.scrollHeight - this.$refs.container.clientHeight
|
|
|
|
}
|
|
|
|
},
|
|
|
|
logLevelUpdated(val) {
|
|
|
|
var payload = {
|
|
|
|
logLevel: Number(val)
|
|
|
|
}
|
|
|
|
this.updateServerSettings(payload)
|
|
|
|
|
2021-11-01 01:10:45 +01:00
|
|
|
this.$root.socket.emit('set_log_listener', this.newServerSettings.logLevel)
|
2021-10-01 01:52:32 +02:00
|
|
|
this.$nextTick(this.updateScroll)
|
|
|
|
},
|
|
|
|
updateServerSettings(payload) {
|
|
|
|
this.$store
|
|
|
|
.dispatch('updateServerSettings', payload)
|
|
|
|
.then((success) => {
|
|
|
|
console.log('Updated Server Settings', success)
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Failed to update server settings', error)
|
|
|
|
})
|
|
|
|
},
|
2021-11-01 01:10:45 +01:00
|
|
|
logEvtReceived(payload) {
|
|
|
|
this.loadedLogs.push(payload)
|
|
|
|
|
|
|
|
// Dont let logs get too large
|
|
|
|
if (this.loadedLogs.length > 5050) {
|
|
|
|
this.loadedLogs = this.loadedLogs.slice(-5000)
|
|
|
|
}
|
|
|
|
},
|
2021-10-01 01:52:32 +02:00
|
|
|
init(attempts = 0) {
|
|
|
|
if (!this.$root.socket) {
|
|
|
|
if (attempts > 10) {
|
|
|
|
return console.error('Failed to setup socket listeners')
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
|
|
|
this.init(++attempts)
|
|
|
|
}, 250)
|
|
|
|
return
|
|
|
|
}
|
2021-11-01 01:10:45 +01:00
|
|
|
|
2021-10-01 01:52:32 +02:00
|
|
|
this.newServerSettings = this.serverSettings ? { ...this.serverSettings } : {}
|
2021-11-01 01:10:45 +01:00
|
|
|
this.$root.socket.on('daily_logs', this.dailyLogsLoaded)
|
|
|
|
this.$root.socket.on('log', this.logEvtReceived)
|
|
|
|
this.$root.socket.emit('set_log_listener', this.newServerSettings.logLevel)
|
|
|
|
this.$root.socket.emit('fetch_daily_logs')
|
|
|
|
},
|
|
|
|
dailyLogsLoaded(lines) {
|
|
|
|
this.loadedLogs = lines
|
2021-10-01 01:52:32 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
updated() {
|
|
|
|
this.$nextTick(this.updateScroll)
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.init()
|
2021-11-01 01:10:45 +01:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
if (!this.$root.socket) return
|
2022-07-08 00:25:52 +02:00
|
|
|
this.$root.socket.emit('remove_log_listener')
|
2021-11-01 01:10:45 +01:00
|
|
|
this.$root.socket.off('daily_logs', this.dailyLogsLoaded)
|
|
|
|
this.$root.socket.off('log', this.logEvtReceived)
|
2021-10-01 01:52:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.logmessage {
|
|
|
|
width: calc(100% - 208px);
|
|
|
|
}
|
|
|
|
</style>
|