# Log Viewer

> A log that follows its newest line, with a filter, level buttons and Wrap, such as a deploy's or a server's.

Page: https://uicontext.com/docs/components/log-viewer

Group: Documents.

## When to use

A log that follows its newest line, with a filter, level buttons and Wrap, such as a deploy's or a server's. Use [Terminal](https://uicontext.com/docs/components/terminal.md) instead when people type commands, not only read lines as they arrive.

## Usage

```ts
import { LogViewer, type LogLine } from "./ui/uicontext/components/LogViewer.ts"

export const BuildLog = <M>(h: Html.H<M>, lines: ReadonlyArray<LogLine>, running: boolean) =>
	LogViewer(h, { props: { label: "Build log", lines, live: running } })
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### A deploy, as it runs

The example the page opens with: Log Viewer in “A deploy, as it runs”.

```ts title="src/demo.ts" source="www/src/examples/log-viewer/demo.ts"
import { Subscription, UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema, Stream } from "effect"
import { LogViewer, type LogLine } from "./ui/uicontext/components/LogViewer.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ wrap: { inlineSize: "100%" } })

const start = Date.parse("2026-12-05T09:14:00.000Z")

// a deploy, written a step at a time; the times and steps are fixed so every visit reads the same
const script: ReadonlyArray<Omit<LogLine, "id" | "time"> & { readonly after: number }> = [
	{ after: 0, level: "info", source: "deploy", message: "Deploy 3f9a2c to production started by Ada Okafor" },
	{ after: 220, level: "debug", source: "build", message: "Restoring cache key node-modules-8e1f… hit" },
	{ after: 1400, level: "info", source: "build", message: "Installing dependencies (1,204 packages)" },
	{ after: 9800, level: "info", source: "build", message: "Compiled 412 modules in 6.2s" },
	{ after: 10120, level: "warn", source: "build", message: "Bundle web/app.js is 812 KB, over the 750 KB budget" },
	{ after: 11800, level: "info", source: "migrate", message: "Running 2 migrations" },
	{ after: 12950, level: "info", source: "migrate", message: "0042_invoice_due_dates.sql applied in 1.1s" },
	{ after: 14010, level: "info", source: "migrate", message: "0043_drop_legacy_plans.sql applied in 0.2s" },
	{ after: 15200, level: "info", source: "rollout", message: "Shifting 10% of traffic to the new version" },
	{ after: 21300, level: "debug", source: "rollout", message: "Health check /healthz → 200 in 41ms (3 of 3 regions)" },
	{ after: 27400, level: "error", source: "api", message: "POST /v1/invoices/send 500: ledger timeout after 30000ms\n    at LedgerClient.post (ledger.ts:88)\n    at sendInvoice (invoices.ts:214)" },
	{ after: 27600, level: "warn", source: "rollout", message: "Error rate 0.8% on the new version, under the 2% limit; carrying on" },
	{ after: 33500, level: "info", source: "rollout", message: "Shifting 50% of traffic to the new version" },
	{ after: 45200, level: "info", source: "rollout", message: "Shifting 100% of traffic to the new version" },
	{ after: 46100, level: "info", source: "deploy", message: "Deploy 3f9a2c finished in 46.1s" },
]

const lineAt = (i: number): LogLine => {
	const step = script[i]!
	return { id: String(i), time: new Date(start + step.after).toISOString(), level: step.level, ...(step.source === undefined ? {} : { source: step.source }), message: step.message }
}

const Message = UiSchema.TaggedEnum({ Wrote: {} })

export const DeployLog = Html.component({
	name: "DeployLog",
	model: Schema.Struct({ count: Schema.Number }),
	message: Message,
}).make({
	init: () => ({ count: 3 }),
	// stands in for the server's stream: the next line, a beat later, until the deploy is done
	subscriptions: ($) => [$.model.count < script.length && Subscription.make("log-tick", Stream.tick("700 millis").pipe(Stream.drop(1), Stream.as(Message.Wrote())))],
	update: {
		Wrote: ($) => $.evolve({ count: Math.min(script.length, $.model.count + 1) }),
	},
	view: (h, model) =>
		h.div.attrs(sx(styles.wrap)).children(
			LogViewer(h, {
				key: "deploy",
				props: {
					label: "Deploy log",
					lines: Array.from({ length: model.count }, (_, i) => lineAt(i)),
					live: model.count < script.length,
					timeZone: "UTC",
					maxHeight: 300,
				},
			}),
		),
})
```

### Finding the failures in a busy log

Type in the filter to narrow the lines and mark the words. The level buttons hide what's noise.

```ts title="src/server.ts" source="www/src/examples/log-viewer/server.ts"
import type { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { LogViewer, type LogLine } from "./ui/uicontext/components/LogViewer.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ wrap: { inlineSize: "100%" } })

const routes = ["GET /v1/projects", "GET /v1/issues?status=open", "POST /v1/comments", "PATCH /v1/issues/ENG-2391", "GET /v1/me"]
const workers = ["api-1", "api-2", "worker-1"]
const start = Date.parse("2026-12-05T14:00:00.000Z")

// an hour of a server's lines, fixed so every visit reads the same: mostly requests, some noise, a few failures
const lines: ReadonlyArray<LogLine> = Array.from({ length: 640 }, (_, i) => {
	const time = new Date(start + i * 5_413).toISOString()
	const source = workers[i % workers.length]!
	if (i % 97 === 41) return { id: String(i), time, level: "error", source, message: `POST /v1/comments 503: search index unavailable (attempt ${(i % 3) + 1} of 3)` }
	if (i % 53 === 7) return { id: String(i), time, level: "warn", source, message: `Slow query on issues (${820 + (i % 7) * 113}ms): SELECT … WHERE project_id = $1 ORDER BY updated_at` }
	if (i % 5 === 3) return { id: String(i), time, level: "debug", source, message: `cache ${i % 2 === 0 ? "hit" : "miss"} issues:list:${i % 11}` }
	const route = routes[i % routes.length]!
	return { id: String(i), time, level: "info", source, message: `${route} 200 in ${12 + (i * 7) % 180}ms` }
})

// a finished log: filter for "503" or "slow", hide Debug and Info to see only what went wrong
export const ServerLog = <M>(h: Html.H<M>) =>
	h.div.attrs(sx(styles.wrap)).children(
		LogViewer(h, { key: "server", props: { label: "api server log", lines, timeZone: "UTC", maxHeight: 360 } }),
	)
```

## API reference

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` (required) | `string` | — | What the log is, for screen readers: "Deploy log". |
| `lines` (required) | `LogLine[]` | — | Every line so far, oldest first. |
| `live` | `boolean` | — | Lines are still coming: a Live mark shows beside the count. |
| `timeZone` | `string` | — | The reader's time zone for the times; the browser's by default. |
| `locale` | `string` | — | For the counts; the browser's by default. |
| `limit` | `number` | `2000` | The most lines drawn; 2000 by default. |
| `maxHeight` | `number` | `420` | The log's tallest, in px, before it scrolls; 420 by default. |

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/log-viewer
```

With npm: `npx shadcn@latest add checkfu/uicontext/log-viewer`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/log-viewer`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/log-viewer`.

It writes these files:

- `src/ui/uicontext/components/Artifact.ts`
- `src/ui/uicontext/components/Attribution.ts`
- `src/ui/uicontext/components/Blocks.ts`
- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/Cite.ts`
- `src/ui/uicontext/components/Conversation.ts`
- `src/ui/uicontext/components/ConversationViewport.ts`
- `src/ui/uicontext/components/CopyButton.ts`
- `src/ui/uicontext/components/EditorBlocks.ts`
- `src/ui/uicontext/components/FileList.ts`
- `src/ui/uicontext/components/FormControls.ts`
- `src/ui/uicontext/components/Glyph.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/InlineNotice.ts`
- `src/ui/uicontext/components/LogViewer.ts`
- `src/ui/uicontext/components/Motion.ts`
- `src/ui/uicontext/components/Popover.ts`
- `src/ui/uicontext/components/Prose.ts`
- `src/ui/uicontext/components/SegmentedControl.ts`
- `src/ui/uicontext/components/ShowText.ts`
- `src/ui/uicontext/components/Spoken.ts`
- `src/ui/uicontext/components/Stream.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/ToolCall.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/cite.stylex.ts`
- `src/ui/uicontext/components/domain/Actor.ts`
- `src/ui/uicontext/components/domain/Chat.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Glyph.ts`
- `src/ui/uicontext/components/domain/Message.ts`
- `src/ui/uicontext/components/domain/Outcome.ts`
- `src/ui/uicontext/components/domain/Record.ts`
- `src/ui/uicontext/components/domain/Run.ts`
- `src/ui/uicontext/components/domain/Time.ts`
- `src/ui/uicontext/components/domain/Upload.ts`
- `src/ui/uicontext/components/editor.stylex.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/touch.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/LogViewer.ts](https://github.com/checkfu/uicontext/blob/main/src/LogViewer.ts)

## Related

- [Editor](https://uicontext.com/docs/components/editor.md) (`editor`): A block editor with a slash menu for headings, lists, to-dos and more.
- [Document Blocks](https://uicontext.com/docs/components/document-blocks.md) (`document-blocks`): Read-only rendering of a document's blocks.
- [Markdown](https://uicontext.com/docs/components/markdown.md) (`markdown`): Renders Markdown with readable type.
- [Code Block](https://uicontext.com/docs/components/code-block.md) (`code-block`): Code to read and copy, with highlighting, a file name and line numbers.
- [JSON Viewer](https://uicontext.com/docs/components/json-viewer.md) (`json-viewer`): A JSON value as a tree to open, search and walk with the arrow keys, such as a webhook's payload or a tool call's result.
- [Diff](https://uicontext.com/docs/components/diff.md) (`diff`): Added and removed lines in a change, side by side or inline.
