Log Viewer
High-throughput streaming log viewer with ANSI color parsing, search, level filtering, and tail auto-scroll.
Keyboard
- ↑↓
- Scroll through log lines
- HomeEnd
- Jump to start or end of logs
- PageUpPageDown
- Scroll by one page
- Escape
- Clear search filter
The CLI also installs the npm packages and registry items it builds on, and reads the style in your components.json to pick the Base UI or Radix build.
"use client"
import { LogViewer, type LogLine } from "@/components/ui/log-viewer"
const LOG_LINES: LogLine[] = [
{ id: "1", timestamp: Date.now() - 3000, level: "info", message: "Build started..." },
{ id: "2", timestamp: Date.now() - 2000, level: "info", message: "\u001b[32mCompiled successfully\u001b[0m in 1.2s" },
{ id: "3", timestamp: Date.now() - 1000, level: "warn", message: "\u001b[33mWarning: asset size exceeds recommended budget\u001b[0m" },
]
export function BuildLogs() {
return (
<LogViewer
lines={LOG_LINES}
height={360}
showLineNumbers
showTimestamps
/>
)
}LogViewer
High-throughput virtualized log viewer with ANSI color parsing, search, level filtering, and tail auto-scroll.
| Prop | Type | Default |
|---|---|---|
defaultFollowbooleanDefaulttrueInitial follow state when uncontrolled. | boolean | true |
defaultLevelstringDefault"all"Initial level filter when uncontrolled. | string | "all" |
defaultSearchstringDefault""Initial search query when uncontrolled. | string | "" |
defaultWrapbooleanDefaultfalseInitial line wrap state when uncontrolled. | boolean | false |
emptyMessageReactNodeDefault"No log lines matching criteria"Message or element displayed when no logs match filters. | ReactNode | "No log lines matching criteria" |
filterablebooleanDefaulttrueWhether to render log level filter buttons in the toolbar. | boolean | true |
followbooleanControlled tail auto-scroll state. | boolean | |
heightnumber | stringDefault400Height of the virtualized log list viewport. | number | string | 400 |
levelstringControlled level filter. | string | |
linesRequiredLogLine[]Array of log entries to display. | LogLine[] | |
onFollowChange(follow: boolean) => voidCalled when follow state changes. | (follow: boolean) => void | |
onLevelChange(level: string) => voidCalled when level filter changes. | (level: string) => void | |
onSearchChange(search: string) => voidCalled when search query changes. | (search: string) => void | |
onWrapChange(wrap: boolean) => voidCalled when line wrap is toggled. | (wrap: boolean) => void | |
rowHeightnumberDefault24Estimated line height in pixels for the virtual list. | number | 24 |
searchstringControlled search query. | string | |
searchablebooleanDefaulttrueWhether to render the search filter input in the toolbar. | boolean | true |
showLineNumbersbooleanDefaulttrueWhether to display line numbers in the gutter. | boolean | true |
showTimestampsbooleanDefaulttrueWhether to display timestamps if present in the log line. | boolean | true |
wrapbooleanControlled line wrap. When false, long messages scroll sideways in one shared viewport; when true, they wrap onto extra lines. | boolean |
Other props go to the <div>.
Streaming follow
Simulates real-time log streaming. When follow is active, new lines automatically scroll into view. Scrolling up pauses follow and shows a floating Jump to latest button.
Search and level filtering
Isolate log lines by log level (such as error or warn) and filter lines matching a search query with a live match count.
ANSI color sequences
Supports 16-color ANSI codes, 256-color lookup, text styling (bold, italic, underline, dim), and safely renders untrusted logs without innerHTML.