ffplayout/frontend/pages/logging.vue

195 lines
4.6 KiB
Vue
Raw Normal View History

2020-04-17 15:02:21 +02:00
<template>
<div class="w-full flex flex-col">
2024-04-16 18:13:28 +02:00
<div class="flex justify-end p-3 h-14">
2024-04-29 10:48:51 +02:00
<div class="join">
<select v-model="errorLevel" class="join-item select select-sm select-bordered w-full max-w-xs">
<option
2024-09-03 16:12:29 +02:00
v-for="(index, value) in indexStore.severityLevels"
:key="index"
:value="value"
2024-09-03 16:12:29 +02:00
:selected="value === errorLevel"
>
{{ value }}
</option>
</select>
2024-04-16 18:13:28 +02:00
<VueDatePicker
v-model="listDate"
:clearable="false"
:hide-navigation="['time']"
:action-row="{ showCancel: false, showSelect: false, showPreview: false }"
:format="calendarFormat"
model-type="yyyy-MM-dd"
auto-apply
2024-04-14 00:01:45 +02:00
:locale="locale"
2024-04-09 17:21:13 +02:00
:dark="colorMode.value === 'dark'"
:ui="{ input: 'join-item input !input-sm !input-bordered !w-[170px] text-right !pe-3' }"
required
/>
<button class="btn btn-sm btn-primary join-item" :title="t('log.download')" @click="downloadLog">
2024-04-29 10:48:51 +02:00
<i class="bi-download" />
</button>
2024-04-16 18:13:28 +02:00
</div>
</div>
<div class="px-3 inline-block h-[calc(100vh-140px)] text-[13px]">
<div
class="bg-base-300 whitespace-pre h-full font-mono overflow-auto p-3"
v-html="filterLogsBySeverity(formatLog(currentLog), errorLevel)"
/>
2023-01-11 10:54:25 +01:00
</div>
2024-04-05 18:51:50 +02:00
</div>
2020-04-17 15:02:21 +02:00
</template>
2023-01-11 10:54:25 +01:00
<script setup lang="ts">
2023-03-22 16:01:58 +01:00
import { storeToRefs } from 'pinia'
2023-01-11 10:54:25 +01:00
const colorMode = useColorMode()
2024-04-16 14:07:50 +02:00
const { locale, t } = useI18n()
2024-09-03 16:12:29 +02:00
const indexStore = useIndex()
2023-01-11 10:54:25 +01:00
useHead({
2024-04-16 14:07:50 +02:00
title: `${t('button.logging')} | ffplayout`,
2023-01-11 10:54:25 +01:00
})
const { id } = storeToRefs(useConfig())
2023-01-11 10:54:25 +01:00
const { $dayjs } = useNuxtApp()
const authStore = useAuth()
const configStore = useConfig()
const currentLog = ref('')
const listDate = ref($dayjs().utcOffset(configStore.utcOffset).format('YYYY-MM-DD'))
const { formatLog } = stringFormatter()
2024-09-03 16:12:29 +02:00
const levelCookie = useCookie('error_level', {
path: '/',
maxAge: 60 * 60 * 24 * 365,
sameSite: 'lax',
})
const errorLevel = computed({
get() {
return levelCookie.value || 'INFO'
},
set(value) {
levelCookie.value = value
},
})
2024-08-22 17:22:20 +02:00
onMounted(async () => {
await getLog()
2023-03-22 16:01:58 +01:00
})
watch([listDate, id], () => {
getLog()
})
const calendarFormat = (date: Date) => {
return $dayjs(date).locale(locale.value).format('ddd L')
}
function filterLogsBySeverity(logString: string, minSeverity: string): string {
2024-09-03 16:12:29 +02:00
const minLevel = indexStore.severityLevels[minSeverity]
const logLines = logString.trim().split(/\r?\n/)
const filteredLogs = logLines.filter((log) => {
const match = log.match(/\[ ?(DEBUG|INFO|WARN|ERROR)\]/)
if (match) {
const logLevel = match[1]
2024-09-03 16:12:29 +02:00
return indexStore.severityLevels[logLevel] >= minLevel
}
return false
})
return filteredLogs.join('\n')
}
2023-01-11 10:54:25 +01:00
async function getLog() {
let date = listDate.value
if (date === $dayjs().utcOffset(configStore.utcOffset).format('YYYY-MM-DD')) {
date = ''
2020-04-17 15:02:21 +02:00
}
2023-01-11 10:54:25 +01:00
await fetch(`/api/log/${configStore.channels[configStore.id].id}?date=${date}`, {
2023-01-11 10:54:25 +01:00
method: 'GET',
headers: authStore.authHeader,
})
.then((response) => response.text())
.then((data) => {
currentLog.value = data
})
.catch(() => {
currentLog.value = ''
})
2020-04-17 15:02:21 +02:00
}
2024-04-29 10:48:51 +02:00
function downloadLog() {
const file = new File(
[formatLog(currentLog.value).replace(/<\/?[^>]+(>|$)/g, '')],
`playout_${listDate.value}.log`,
{
type: 'text/plain',
}
)
const link = document.createElement('a')
const url = URL.createObjectURL(file)
link.href = url
link.download = file.name
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(url)
}
2020-04-17 15:02:21 +02:00
</script>
<style>
.log-time {
color: #666864;
}
.log-number {
2024-04-15 17:39:41 +02:00
color: var(--my-yellow);
}
.log-addr {
2024-04-15 17:39:41 +02:00
color: var(--my-purple);
font-weight: 500;
}
.log-cmd {
2024-04-15 17:39:41 +02:00
color: var(--my-blue);
}
2020-04-27 16:07:28 +02:00
.log-info {
2024-04-15 17:39:41 +02:00
color: var(--my-green);
2020-04-27 16:07:28 +02:00
}
.log-warning {
color: #ff8700;
2020-04-27 16:07:28 +02:00
}
.log-error {
color: #d32828;
2020-04-27 16:07:28 +02:00
}
.log-debug {
color: #6e99c7;
2020-04-27 16:07:28 +02:00
}
2022-01-25 10:32:29 +01:00
.log-decoder {
color: #56efff;
2022-01-25 10:32:29 +01:00
}
.log-encoder {
color: #45ccee;
2022-01-25 10:32:29 +01:00
}
.log-server {
color: #23cbdd;
2022-01-25 10:32:29 +01:00
}
2020-04-17 15:02:21 +02:00
</style>