Log viewer
Numbered, timestamped log lines with level labels, warning and error rows tinted, in a scrollable panel with an optional live status.
pnpm dlx shadcn@latest add @haze/log-viewer---
import { cn } from "../../../lib/haze/utils";
import Status from "./status.astro";
type Level = "debug" | "info" | "warn" | "error";
interface Line {
/** Time as it should read, such as "14:02:07". */
time?: string;
level?: Level;
text: string;
}
interface Props {
/** Visible title; also the accessible name of the scroll region. */
title?: string;
/** Source shown after the title, such as a command or a file. */
source?: string;
lines?: Line[];
/** Shows a pulsing "Live" status for a stream that is still running. */
live?: boolean;
/** Text of the footer band. Leave empty to hide it. */
footer?: string;
class?: string;
}
const {
title = "web",
source = "pnpm dev --port 4321",
lines = [
{ time: "14:02:05", level: "info", text: "Starting dev server" },
{ time: "14:02:06", level: "debug", text: "Loaded 3 env files from .env, .env.local" },
{ time: "14:02:07", level: "info", text: "Ready on http://localhost:4321 in 812 ms" },
{ time: "14:02:31", level: "warn", text: "Slow request: GET /reports took 2.4 s" },
{ time: "14:03:12", level: "error", text: "Error: connect ECONNREFUSED 127.0.0.1:5432 (database is not running)" },
{ time: "14:03:13", level: "info", text: "Retrying in 5 s" },
],
live = true,
footer = "Last 6 lines",
class: className,
} = Astro.props;
const levels: Record<Level, { label: string; tone: string }> = {
debug: { label: "DBG", tone: "text-muted-foreground" },
info: { label: "INF", tone: "text-brand" },
warn: { label: "WRN", tone: "text-warning" },
error: { label: "ERR", tone: "text-destructive" },
};
const levelNames: Record<Level, string> = { debug: "debug", info: "info", warn: "warning", error: "error" };
---
<div class={cn("flex flex-col overflow-hidden rounded-xl border border-border bg-card", className)}>
<div class="flex min-h-11 items-center justify-between gap-2 border-b border-border bg-muted/40 px-4 py-1">
<div class="min-w-0">
<p class="truncate text-[0.8125rem]/5 font-medium text-foreground">{title}</p>
{source && <p class="truncate font-mono text-xs/4 text-muted-foreground">{source}</p>}
</div>
{live && <Status variant="success" label="Live" pulse class="shrink-0 text-xs" />}
</div>
<div
role="region"
aria-label={`${title} log`}
tabindex="0"
class="max-h-72 overflow-y-auto py-3.5 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
>
<ol class="font-mono text-xs/5">
{
lines.map((line, i) => (
<li
class={cn(
"grid grid-cols-[2rem_auto_1fr] gap-x-3 px-4 py-px sm:grid-cols-[2rem_auto_auto_1fr]",
line.level === "error" && "bg-destructive/8",
line.level === "warn" && "bg-warning/8",
)}
>
<span aria-hidden="true" class="text-right text-muted-foreground/60 tabular-nums select-none">{i + 1}</span>
{line.time ? <span class="text-muted-foreground tabular-nums max-sm:hidden">{line.time}</span> : <span class="max-sm:hidden" />}
{line.level ? (
<span class={cn("font-medium", levels[line.level].tone)}>
<span aria-hidden="true">{levels[line.level].label}</span>
<span class="sr-only">{levelNames[line.level]}</span>
</span>
) : (
<span />
)}
<span class="min-w-0 break-words whitespace-pre-wrap text-foreground">{line.text}</span>
</li>
))
}
</ol>
</div>
{footer && <p class="border-t border-border px-4 py-2 text-[0.8125rem]/5 text-muted-foreground">{footer}</p>}
</div>When to use
- An admin or developer tool shows a server's or a job's output
- Readers need to spot warnings and errors in a stream of plain lines
When not to use
- The content is a command to copy. Use snippet or code-block.
- The panel imitates a shell session with prompts. Use terminal-window.
Installation
Add the Haze registry to components.json once, then install Log viewer with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/log-viewernpx shadcn@latest add @haze/log-vieweryarn dlx shadcn@latest add @haze/log-viewerbunx --bun shadcn@latest add @haze/log-viewerFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| title | string | "web" | Visible title; also names the scroll region. |
| source | string | "pnpm dev --port 4321" | Command or file the lines come from. |
| lines | { time?: string; level?: "debug" | "info" | "warn" | "error"; text: string }[] | – | Log lines, oldest first. |
| live | boolean | true | Shows a pulsing Live status for a running stream. |
| footer | string | "Last 6 lines" | Text of the footer band; empty hides it. |
| class | string | – | Additional classes on the panel. |
Keyboard interactions
- Tab, then arrow keys
- Focus the log and scroll it.
Accessibility
- The scroll region is focusable and named after the log, so keyboard users can scroll it.
- Levels are read as words (warning, error); the three-letter codes and line numbers are hidden from assistive technology.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Log viewer" with `npx shadcn@latest add @haze/log-viewer`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import LogViewer from "@/components/haze/ui/log-viewer.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/log-viewer.md
Customize with real content
Adapt the Haze log-viewer ui for our product. Replace the demo values of these props with our real content: title, source, lines, live, footer, class. Keep the layout, the heading level rules and these accessibility details: The scroll region is focusable and named after the log, so keyboard users can scroll it. Levels are read as words (warning, error); the three-letter codes and line numbers are hidden from assistive technology. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using log-viewer, check it fits: use it when an admin or developer tool shows a server's or a job's output; readers need to spot warnings and errors in a stream of plain lines. Avoid it when the content is a command to copy. use snippet or code-block.; the panel imitates a shell session with prompts. use terminal-window.. Alternatives: @haze/terminal-window, @haze/code-block, @haze/timeline.
Dependencies
- @haze/status
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.