Log
A monospace log display container that supports incremental appending and "stick-to-bottom" auto-scrolling, suitable for consoles / build output scenarios.
Basic Usage
Basic log stream
Provide data via the lines property (or the lines attribute as a JSON string); when appending, only the new lines are rendered incrementally — existing nodes are not rebuilt.
Line Numbers
Show line numbers
Appending and Auto-Scroll
Appending log stream (stick-to-bottom auto-scroll)
Appends a log line every 1.2s; auto-scroll happens only when pinned to the bottom, and scrolling up to read history does not interrupt it.
Disabling Auto-Scroll
auto-scroll=false
With auto-scroll="false", appended content does not auto-scroll to the bottom.
Empty State
Empty log
An empty lines shows the empty-state placeholder; the copy follows the locale (overridable via empty-text).
Custom empty text
empty-text overrides the default empty-state copy (default: "No logs").
Loading History on Scroll-Up
require-more pagination
Scrolling to the top fires oas-require-more (detail { from: 'top' }); after a simulated delay, 10 older lines are prepended (key-aligned reconcile — existing rows are not rebuilt), line numbers re-flow and the reading position is preserved.
Line Highlight
Keyword / regex highlight
The highlight JSON array: strings are literal keywords, pattern entries are regexes (escape backslashes as JSON, e.g. \\d); matches are wrapped in a mark span (token semantic background) and all text goes through textContent to prevent injection.
Search Filter
Keyword search filter
A non-empty keyword shows only matching lines (case-insensitive), with matched fragments wrapped in a mark highlight (same visual system as the highlight channel); line numbers still show the original indices. The component fires oas-search (detail { keyword, matched, total }) so the host can display a match count. Clearing the input restores all lines; the host's lines data is never modified.
Level Colors
levels semantic colors
The levels JSON array aligns with lines by index: info / success / warning / error map to token semantic colors (dark-theme aware), with aliases like warn / fatal; unknown levels are not colored.
ANSI Coloring
ANSI escape sequence coloring
With ansi set, each line is parsed for ANSI SGR escape sequences: 16 / 256 / truecolor foreground and background colors plus bold / dim / italic / underline / inverse; escape codes are stripped from the displayed text. The ANSI foreground takes precedence over the levels semantic line color, and keyword / highlight marks still apply (inheriting the ANSI foreground). The palette uses light-dark() so dark mode switches to readable colors automatically.
Scope and boundaries:
- Foreground / background: 16 colors
30-37/90-97(bright) /40-47/100-107, rendered via the built-inlight-dark()palette (CSS classes, one readable set per theme, overridable per color with the--ansi-*CSS variables set on theoas-logelement);38;5;n/48;5;n(256 colors) and38;2;r;g;b/48;2;r;g;b(truecolor) are rendered as inline styles, with foreground colors auto-corrected for perceptual contrast in each theme and colored backgrounds picking the best foreground (16-color backgrounds guarantee at least one of black / white passes; arbitrary truecolor backgrounds can only be optimized, extreme mid-tones may need an explicit host foreground). - Styles:
1bold,2dim,3italic,4underline,7inverse;0resets everything,22/23/24/27turn each style off (39/49clear the foreground / background back to inherited colors). - Precedence: a segment with an ANSI foreground color wins (overriding the
levelssemantic line color); segments without an ANSI foreground keep thelevels/ host text color.keyword/highlightmarks are wrapped inside the ANSI segment and inherit its foreground, so highlighting never loses the color. - Safety & performance: sequences are parsed into plain-text segments rendered with classes / inline styles —
innerHTMLis never used, so hostile text (<script>, quotes,&) is displayed literally; non-SGR CSI / OSC / multi-byte ESC sequences and C0 control characters are stripped as well (tabs are preserved) and never leak into the DOM. Unknown / invalid parameters are ignored without affecting the rest of the line. Parsing only runs when a line's content or a channel changes; appends perform zero rebuilds while channels stay unchanged. - Boundaries: keyword filtering matches the visible text (escape sequences are stripped first when
ansiis on), so color codes cannot hide a match; SGR state resets per line (colors do not carry across lines), so multi-line colored output should include escapes on each line. The 16-color palette is tuned against the page background--oas-color-bg; on elevated backgrounds or withdim, override the--ansi-*variables if stricter contrast is needed. No terminal emulation (input, cursor, OSC 8 hyperlinks).
Loading and scrollTo
loading + scrollTo()
The loading attribute shows an overlay and syncs aria-busy; the scrollTo('top' | 'bottom' | px) method lets external buttons jump around.
Font Size
Font size follows the outer context (inherited) by default; override with the CSS variable --oas-log-font (e.g. 18px).
Events and Methods
oas-require-more: fired when scrolling into the top/bottom threshold zone (detail{ from: 'top' | 'bottom' }). Edge-triggered — no repeated firing while staying in the zone, reset after leaving; thresholds controlled byoffset-top/offset-bottom(px).oas-search: search filter report (detail{ keyword, matched, total }) — fired when the keyword or the data changes (deduped for identical state);matchedis the current number of matching lines andtotalthe total lines; the filter window is the currently loaded lines (compatible with paginated loading).scrollTo('top' | 'bottom' | number): scrolls the viewport to top / bottom / a pixel offset, for external "back to bottom" buttons.loading: overlay mask on the viewport, syncsaria-busy; copy follows the locale (loading.loading).levels/highlight/keyword: per-line level semantic colors / keyword·regex highlight / search filter channels (JSON attributes, see demos above). A non-emptykeywordshows only matching lines (case-insensitive) and highlights matched fragments with a mark span; filtering never modifies the host'slines, line numbers and levels stay aligned to the original indices, and clearing restores everything.ansi: ANSI SGR escape sequence coloring switch (off by default), supporting 16 / 256 / truecolor foreground and background colors plus common styles — see the "ANSI Coloring" section.
When history lines are prepended, the reconcile aligns rows by content key: existing row nodes are reused, line numbers re-flow, and the viewport reading position is compensated automatically.
API
oas-log
Attributes
| Attribute | Description | Type | Default |
|---|---|---|---|
ansi | Parse and render ANSI SGR escape sequences per line (boolean, off by default): 16-color foreground/background (30-37/90-97/40-47/100-107, light-dark() palette), 256 colors (38;5;n/48;5;n) and truecolor (38;2;r;g;b/48;2;r;g;b, inline style), plus bold/dim/italic/underline/inverse and reset; non-SGR CSI/OSC/multi-byte ESC sequences and C0 control characters are stripped to prevent leakage (tabs preserved); the ANSI foreground overrides the per-line levels semantic color, keyword/highlight marks still apply (inheriting the ANSI foreground) | boolean | — |
auto-scroll | Auto-scroll to bottom on append (only when stuck to the bottom) | string | true |
empty-text | Empty state text (overrides the locale default) | — | — |
highlight | Line highlight rules (JSON array): string = literal keyword; { text } / { pattern, flags } = regex; matches are wrapped with a mark background (warning token) | string | — |
keyword | Search filter keyword: when non-empty, only matching lines are shown (case-insensitive) and matched fragments get a mark highlight (same visual system as highlight); line numbers / levels stay aligned to the original indices, clearing restores all lines without modifying the host's lines | string | — |
levels | Line levels (JSON array, index-aligned with lines): info/success/warning/error (aliases like warn/fatal normalized), mapped to semantic color tokens | string | — |
line-number | Show the left line number column | boolean | — |
lines | Log lines JSON string (attribute channel) | string[] | [] |
loading | Loading state (viewport overlay + spinner + aria-busy) | boolean | — |
offset-bottom | Distance from the bottom that counts as reaching it (px, fires oas-require-more with from=bottom, default 0) | — | — |
offset-top | Distance from the top that counts as reaching it (px, fires oas-require-more with from=top, default 0) | — | — |
Methods
| Method | Signature | Description |
|---|---|---|
scrollTo | scrollTo(target?: (ScrollToOptions & { position?: 'top' | 'bottom' }) | 'top' | 'bottom' | number): void | Scroll the viewport: 'top' goes to the top, 'bottom' to the bottom, and a number is the pixel scrollTop |
Events
| Event | Description |
|---|---|
oas-require-more | Fired once when scrolling enters the top/bottom threshold edge (not repeatedly while staying, re-arms after leaving), detail: { from: "top" | "bottom" }; for loading history/new entries |
oas-search | Search filter report: fired when the keyword or the data changes (deduped for identical state), detail: { keyword, matched, total } (matched = matching line count, total = total lines; the filter window is the currently loaded lines) |
CSS Variables
| CSS Variable | Default |
|---|---|
--oas-log-font | inherit |
--oas-log-loading-mask | color-mix(in srgb, var(--oas-color-bg) 65%, transparent) |
--oas-log-mark-bg | color-mix(in srgb, var(--oas-color-warning) 18%, transparent) |
--oas-log-mark-color | var(--oas-color-warning-text) |
Parts: ::part(viewport) scroll viewport, ::part(log) log content, ::part(row) a single row, ::part(line-number) line number, ::part(line) line text, ::part(empty) empty state.