61 lines
3.3 KiB
Vue
61 lines
3.3 KiB
Vue
<script setup lang="ts">
|
|
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
|
|
import { MetadataList } from "@/components/ui/metadata-list";
|
|
import { fmtValue, LEVEL_COLOR, levelKind, rowClass, shortTime, type LogEntry } from "@/lib/log";
|
|
|
|
/**
|
|
* Log entries as a table: time, level, stage, service and message, with an
|
|
* entry's remaining fields opened beneath it. The task log and the
|
|
* instance-wide log page render the same entries through it.
|
|
*/
|
|
const props = withDefaults(
|
|
defineProps<{
|
|
entries: LogEntry[];
|
|
rowKey: (entry: LogEntry) => string;
|
|
storageKey: string;
|
|
/** Fields the page itself already names, such as the task it is about. */
|
|
omit?: string[];
|
|
/** Shows service and component columns by default, for logs spanning
|
|
* services; a task's own log shows its stage instead. */
|
|
services?: boolean;
|
|
}>(),
|
|
{ omit: () => [], services: false },
|
|
);
|
|
|
|
const columns: DataTableColumn<LogEntry>[] = [
|
|
{ id: "time", label: "Time", fixed: true, class: "w-0 whitespace-nowrap" },
|
|
{ id: "level", label: "Level", fixed: true, class: "w-0" },
|
|
{ id: "service", label: "Service", hidden: !props.services, class: "w-0 whitespace-nowrap" },
|
|
{ id: "component", label: "Component", hidden: !props.services, class: "w-0 whitespace-nowrap" },
|
|
{ id: "stage", label: "Stage", hidden: props.services, class: "w-0 whitespace-nowrap" },
|
|
{ id: "message", label: "Message", fixed: true },
|
|
];
|
|
// received_at restates the time; the rest have columns.
|
|
const shown = new Set(["received_at", "stage", "service", "component", ...props.omit]);
|
|
const field = (entry: LogEntry, name: string) => fmtValue(entry.fields?.[name] ?? "");
|
|
const details = (entry: LogEntry) =>
|
|
Object.entries(entry.fields ?? {})
|
|
.filter(([k]) => !shown.has(k))
|
|
.map(([label, value]) => ({ label, value: fmtValue(value), mono: true }));
|
|
</script>
|
|
|
|
<template>
|
|
<DataTable :columns="columns" :rows="entries" :row-key="rowKey" :storage-key="storageKey" :row-class="(e) => rowClass(e.level)" sticky-header>
|
|
<template #cell-time="{ row }"><span class="font-mono text-xs text-fg-subtle">{{ shortTime(row.time) }}</span></template>
|
|
<template #cell-level="{ row }">
|
|
<span class="text-micro font-semibold tracking-[0.04em]" :class="LEVEL_COLOR[levelKind(row.level)]">{{ (row.level || "info").toUpperCase() }}</span>
|
|
</template>
|
|
<template #cell-service="{ row }"><span class="block max-w-40 truncate font-mono text-xs text-fg-muted">{{ field(row, "service") }}</span></template>
|
|
<template #cell-component="{ row }"><span class="block max-w-48 truncate font-mono text-xs text-fg-muted">{{ field(row, "component") }}</span></template>
|
|
<template #cell-stage="{ row }"><span class="block max-w-48 truncate font-mono text-xs text-fg-muted" :title="field(row, 'stage')">{{ field(row, "stage") }}</span></template>
|
|
<template #cell-message="{ row }">
|
|
<span class="font-mono text-xs [overflow-wrap:anywhere]">{{ row.message || row.msg || "" }}</span>
|
|
<span v-if="details(row).length" class="ml-2 text-xs text-fg-subtle">{{ details(row).length }} field{{ details(row).length === 1 ? "" : "s" }}</span>
|
|
</template>
|
|
<template #detail="{ row }">
|
|
<MetadataList v-if="details(row).length" :rows="details(row)" class="text-xs" />
|
|
<span v-else class="text-xs text-fg-subtle">No fields</span>
|
|
</template>
|
|
</DataTable>
|
|
</template>
|