|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { LogLevel } from 'evlog' |
| 3 | +import { log, setMinLevel } from 'evlog/client' |
| 4 | +
|
| 5 | +const levels: LogLevel[] = ['debug', 'info', 'warn', 'error'] |
| 6 | +
|
| 7 | +const minLevel = ref<LogLevel>('debug') |
| 8 | +
|
| 9 | +const order: Record<LogLevel, number> = { |
| 10 | + debug: 0, |
| 11 | + info: 1, |
| 12 | + warn: 2, |
| 13 | + error: 3, |
| 14 | +} |
| 15 | +
|
| 16 | +function passes(level: LogLevel): boolean { |
| 17 | + return order[level] >= order[minLevel.value] |
| 18 | +} |
| 19 | +
|
| 20 | +function applyMinLevel(level: LogLevel) { |
| 21 | + minLevel.value = level |
| 22 | + setMinLevel(level) |
| 23 | +} |
| 24 | +
|
| 25 | +function emitAt(level: LogLevel) { |
| 26 | + const payload = { panel: 'min-level', ts: Date.now() } |
| 27 | + if (level === 'debug') { |
| 28 | + log.debug(payload) |
| 29 | + } else if (level === 'info') { |
| 30 | + log.info(payload) |
| 31 | + } else if (level === 'warn') { |
| 32 | + log.warn('playground', 'warn sample') |
| 33 | + } else { |
| 34 | + log.error('playground', 'error sample') |
| 35 | + } |
| 36 | +} |
| 37 | +
|
| 38 | +onMounted(() => { |
| 39 | + const raw = useRuntimeConfig().public.evlog as { minLevel?: LogLevel } | undefined |
| 40 | + const fromConfig = raw?.minLevel |
| 41 | + if (fromConfig && levels.includes(fromConfig)) { |
| 42 | + minLevel.value = fromConfig |
| 43 | + setMinLevel(fromConfig) |
| 44 | + } |
| 45 | +}) |
| 46 | +</script> |
| 47 | + |
| 48 | +<template> |
| 49 | + <ClientOnly> |
| 50 | + <div class="max-w-3xl space-y-6"> |
| 51 | + <div |
| 52 | + class="rounded-lg border border-[var(--ui-border)] bg-elevated p-5 space-y-4" |
| 53 | + > |
| 54 | + <div> |
| 55 | + <p class="text-xs font-medium text-highlighted uppercase tracking-wide"> |
| 56 | + Minimum level |
| 57 | + </p> |
| 58 | + <p class="text-xs text-muted mt-1 leading-relaxed"> |
| 59 | + Only the global client <code class="text-[11px]">log.*</code> API is filtered. Open DevTools and watch the console: levels below the threshold produce no output and no transport when ingest is enabled. |
| 60 | + </p> |
| 61 | + </div> |
| 62 | + |
| 63 | + <div class="flex flex-wrap gap-2"> |
| 64 | + <UButton |
| 65 | + v-for="lvl in levels" |
| 66 | + :key="lvl" |
| 67 | + size="sm" |
| 68 | + :variant="minLevel === lvl ? 'solid' : 'outline'" |
| 69 | + :color="minLevel === lvl ? 'primary' : 'neutral'" |
| 70 | + @click="applyMinLevel(lvl)" |
| 71 | + > |
| 72 | + {{ lvl }} |
| 73 | + </UButton> |
| 74 | + </div> |
| 75 | + |
| 76 | + <p class="text-[11px] text-muted leading-relaxed"> |
| 77 | + <span class="text-highlighted">Passes:</span> |
| 78 | + {{ levels.filter(l => passes(l)).join(', ') }} |
| 79 | + </p> |
| 80 | + <p class="text-[11px] text-muted leading-relaxed"> |
| 81 | + <code class="text-[11px]">log.debug()</code> uses <code class="text-[11px]">console.log</code> in the browser so lines show with the default console filter (payload still has <code class="text-[11px]">level: "debug"</code>). |
| 82 | + </p> |
| 83 | + </div> |
| 84 | + |
| 85 | + <div |
| 86 | + class="rounded-lg border border-[var(--ui-border)] bg-elevated p-5 space-y-4" |
| 87 | + > |
| 88 | + <p class="text-xs font-medium text-highlighted uppercase tracking-wide"> |
| 89 | + Trigger logs |
| 90 | + </p> |
| 91 | + <div class="flex flex-wrap gap-2"> |
| 92 | + <UButton |
| 93 | + v-for="lvl in levels" |
| 94 | + :key="`emit-${lvl}`" |
| 95 | + size="sm" |
| 96 | + variant="soft" |
| 97 | + :color="lvl === 'error' ? 'error' : lvl === 'warn' ? 'warning' : lvl === 'info' ? 'primary' : 'neutral'" |
| 98 | + @click="emitAt(lvl)" |
| 99 | + > |
| 100 | + log.{{ lvl }}() |
| 101 | + </UButton> |
| 102 | + </div> |
| 103 | + <p class="text-[11px] text-muted"> |
| 104 | + Set minimum to <code class="text-[11px]">warn</code>, then trigger <code class="text-[11px]">log.info</code> — nothing should appear. Switch back to <code class="text-[11px]">debug</code> and trigger again to verify. |
| 105 | + </p> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + <template #fallback> |
| 109 | + <p class="text-sm text-muted"> |
| 110 | + Loading… |
| 111 | + </p> |
| 112 | + </template> |
| 113 | + </ClientOnly> |
| 114 | +</template> |
0 commit comments