2020-04-17 09:02:21 -04:00
|
|
|
<template>
|
2024-04-18 05:49:39 -04:00
|
|
|
<div class="w-full flex flex-col">
|
2024-04-16 12:13:28 -04:00
|
|
|
<div class="flex justify-end p-3 h-14">
|
2024-04-29 04:48:51 -04:00
|
|
|
<div class="join">
|
2024-06-25 11:12:08 -04:00
|
|
|
<select v-model="errorLevel" class="join-item select select-sm select-bordered w-full max-w-xs">
|
|
|
|
<option
|
2024-09-03 10:12:29 -04:00
|
|
|
v-for="(index, value) in indexStore.severityLevels"
|
2024-06-25 11:12:08 -04:00
|
|
|
:key="index"
|
|
|
|
:value="value"
|
2024-09-03 10:12:29 -04:00
|
|
|
:selected="value === errorLevel"
|
2024-06-25 11:12:08 -04:00
|
|
|
>
|
|
|
|
{{ value }}
|
|
|
|
</option>
|
|
|
|
</select>
|
2024-04-16 12:13:28 -04:00
|
|
|
<VueDatePicker
|
2024-04-09 09:45:17 -04:00
|
|
|
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-13 18:01:45 -04:00
|
|
|
:locale="locale"
|
2024-04-09 11:21:13 -04:00
|
|
|
:dark="colorMode.value === 'dark'"
|
2024-09-24 09:02:54 -04:00
|
|
|
:ui="{ input: 'join-item input !input-sm !input-bordered !w-[170px] text-right !pe-3' }"
|
2024-04-09 09:45:17 -04:00
|
|
|
required
|
|
|
|
/>
|
2024-10-03 11:54:24 -04:00
|
|
|
<button class="btn btn-sm btn-primary join-item" :title="t('log.reload')" @click="getLog()">
|
2024-10-03 08:51:40 -04:00
|
|
|
<i class="bi-arrow-repeat" />
|
|
|
|
</button>
|
2024-08-27 05:16:58 -04:00
|
|
|
<button class="btn btn-sm btn-primary join-item" :title="t('log.download')" @click="downloadLog">
|
2024-04-29 04:48:51 -04:00
|
|
|
<i class="bi-download" />
|
|
|
|
</button>
|
2024-04-16 12:13:28 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="px-3 inline-block h-[calc(100vh-140px)] text-[13px]">
|
2024-10-23 09:09:46 -04:00
|
|
|
<div id="log-container" class="bg-base-300 whitespace-pre h-full font-mono overflow-auto p-3">
|
|
|
|
<div id="log-content" v-html="filterLogsBySeverity(formatLog(currentLog), errorLevel)" />
|
|
|
|
</div>
|
2023-01-11 04:54:25 -05:00
|
|
|
</div>
|
2024-04-05 12:51:50 -04:00
|
|
|
</div>
|
2020-04-17 09:02:21 -04:00
|
|
|
</template>
|
|
|
|
|
2023-01-11 04:54:25 -05:00
|
|
|
<script setup lang="ts">
|
2023-03-22 11:01:58 -04:00
|
|
|
import { storeToRefs } from 'pinia'
|
2023-01-11 04:54:25 -05:00
|
|
|
|
2024-04-09 09:45:17 -04:00
|
|
|
const colorMode = useColorMode()
|
2024-04-16 08:07:50 -04:00
|
|
|
const { locale, t } = useI18n()
|
2024-04-09 09:45:17 -04:00
|
|
|
|
2024-09-03 10:12:29 -04:00
|
|
|
const indexStore = useIndex()
|
|
|
|
|
2023-01-11 04:54:25 -05:00
|
|
|
useHead({
|
2024-04-16 08:07:50 -04:00
|
|
|
title: `${t('button.logging')} | ffplayout`,
|
2023-01-11 04:54:25 -05:00
|
|
|
})
|
|
|
|
|
2024-10-01 15:33:18 -04:00
|
|
|
const { i } = storeToRefs(useConfig())
|
2023-01-11 07:41:22 -05:00
|
|
|
|
2023-01-11 04:54:25 -05: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 10:12:29 -04: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-06-25 11:12:08 -04:00
|
|
|
|
2024-08-22 11:22:20 -04:00
|
|
|
onMounted(async () => {
|
|
|
|
await getLog()
|
2023-03-22 11:01:58 -04:00
|
|
|
})
|
|
|
|
|
2024-10-01 15:33:18 -04:00
|
|
|
watch([listDate, i], () => {
|
2023-01-11 07:41:22 -05:00
|
|
|
getLog()
|
|
|
|
})
|
|
|
|
|
2024-04-09 09:45:17 -04:00
|
|
|
const calendarFormat = (date: Date) => {
|
2024-10-23 09:09:46 -04:00
|
|
|
return $dayjs(date).locale(locale.value).format('ddd L')
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollTo() {
|
|
|
|
const parent = document.getElementById('log-container')
|
|
|
|
const child = document.getElementById('log-content')
|
|
|
|
|
|
|
|
if (child && parent) {
|
|
|
|
parent.scrollTop = child.scrollHeight
|
|
|
|
}
|
2024-04-09 09:45:17 -04:00
|
|
|
}
|
|
|
|
|
2024-06-25 11:12:08 -04:00
|
|
|
function filterLogsBySeverity(logString: string, minSeverity: string): string {
|
2024-09-03 10:12:29 -04:00
|
|
|
const minLevel = indexStore.severityLevels[minSeverity]
|
2024-06-25 11:12:08 -04:00
|
|
|
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 10:12:29 -04:00
|
|
|
return indexStore.severityLevels[logLevel] >= minLevel
|
2024-06-25 11:12:08 -04:00
|
|
|
}
|
2024-10-27 12:23:21 -04:00
|
|
|
return true
|
2024-06-25 11:12:08 -04:00
|
|
|
})
|
|
|
|
return filteredLogs.join('\n')
|
|
|
|
}
|
|
|
|
|
2023-01-11 04:54:25 -05:00
|
|
|
async function getLog() {
|
|
|
|
let date = listDate.value
|
|
|
|
|
|
|
|
if (date === $dayjs().utcOffset(configStore.utcOffset).format('YYYY-MM-DD')) {
|
|
|
|
date = ''
|
2020-04-17 09:02:21 -04:00
|
|
|
}
|
2023-01-11 04:54:25 -05:00
|
|
|
|
2024-10-01 15:33:18 -04:00
|
|
|
await fetch(`/api/log/${configStore.channels[configStore.i].id}?date=${date}`, {
|
2023-01-11 04:54:25 -05:00
|
|
|
method: 'GET',
|
|
|
|
headers: authStore.authHeader,
|
|
|
|
})
|
|
|
|
.then((response) => response.text())
|
|
|
|
.then((data) => {
|
|
|
|
currentLog.value = data
|
2024-10-23 09:09:46 -04:00
|
|
|
|
|
|
|
nextTick(() => {
|
|
|
|
scrollTo()
|
|
|
|
})
|
2023-01-11 04:54:25 -05:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
currentLog.value = ''
|
|
|
|
})
|
2020-04-17 09:02:21 -04:00
|
|
|
}
|
2024-04-29 04:48:51 -04: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 09:02:21 -04:00
|
|
|
</script>
|
|
|
|
|
2024-04-09 09:45:17 -04:00
|
|
|
<style>
|
2022-05-15 15:53:02 -04:00
|
|
|
.log-time {
|
2024-04-09 09:45:17 -04:00
|
|
|
color: #666864;
|
2022-05-15 15:53:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.log-number {
|
2024-04-15 11:39:41 -04:00
|
|
|
color: var(--my-yellow);
|
2022-05-15 15:53:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.log-addr {
|
2024-04-15 11:39:41 -04:00
|
|
|
color: var(--my-purple);
|
2022-05-15 15:53:02 -04:00
|
|
|
font-weight: 500;
|
|
|
|
}
|
|
|
|
|
|
|
|
.log-cmd {
|
2024-04-15 11:39:41 -04:00
|
|
|
color: var(--my-blue);
|
2022-05-15 15:53:02 -04:00
|
|
|
}
|
|
|
|
|
2020-04-27 10:07:28 -04:00
|
|
|
.log-info {
|
2024-04-15 11:39:41 -04:00
|
|
|
color: var(--my-green);
|
2020-04-27 10:07:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.log-warning {
|
2024-04-09 09:45:17 -04:00
|
|
|
color: #ff8700;
|
2020-04-27 10:07:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.log-error {
|
2024-04-09 09:45:17 -04:00
|
|
|
color: #d32828;
|
2020-04-27 10:07:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
.log-debug {
|
2024-04-09 09:45:17 -04:00
|
|
|
color: #6e99c7;
|
2020-04-27 10:07:28 -04:00
|
|
|
}
|
|
|
|
|
2022-01-25 04:32:29 -05:00
|
|
|
.log-decoder {
|
2024-04-09 09:45:17 -04:00
|
|
|
color: #56efff;
|
2022-01-25 04:32:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
.log-encoder {
|
2024-04-09 09:45:17 -04:00
|
|
|
color: #45ccee;
|
2022-01-25 04:32:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
.log-server {
|
2024-04-09 09:45:17 -04:00
|
|
|
color: #23cbdd;
|
2022-01-25 04:32:29 -05:00
|
|
|
}
|
2020-04-17 09:02:21 -04:00
|
|
|
</style>
|