Skip to content

LogViewer

KeyAction
/ kScroll up one line
/ jScroll down one line
Home / gJump to top
End / GJump to bottom and enable follow
PgUpPage up
PgDnPage down
fToggle follow mode
cClear all log entries
EnterSelect the highlighted line (fires onSelect)

Scrolling up automatically disables follow mode. End / G re-enables it.

When follow mode is active, new log entries scroll the view to the bottom automatically. It disables on any manual scroll. Call SetFollow(true) to enable programmatically.

SetFilter(pattern string) applies a regex to the log stream — only matching lines are shown. An empty pattern clears the filter and shows all entries.

Append entries from a goroutine using Append — it is safe to call from any goroutine. LogViewer calls QueueUpdateDraw internally.

LogViewer preview

LogViewer displays streaming log entries with level-based coloring, regex filtering, and follow mode. Append entries from any goroutine via Append; the viewer calls QueueUpdateDraw internally.

Constructor func NewLogViewer() *LogViewer

Usage

log := components.NewLogViewer().
SetMaxEntries(5000).
SetShowTimestamp(true).
SetShowLevel(true).
SetTimestampFormat("15:04:05").
SetFollow(true).
SetMinLevel(components.LogLevelInfo)
log.AddEntry(components.LogEntry{Level: components.LogLevelInfo, Message: "server started"})
log.AddEntry(components.LogEntry{Level: components.LogLevelError, Message: "connection lost"})
fmt.Println(log != nil)

Methods

Method Signature Description
AddEntry func (v *LogViewer) AddEntry(entry LogEntry) *LogViewer AddEntry adds a log entry
Clear func (v *LogViewer) Clear() *LogViewer Clear removes all entries
ClearFilter func (v *LogViewer) ClearFilter() *LogViewer ClearFilter removes all filters
Debug func (v *LogViewer) Debug(message string) *LogViewer Debug logs a debug message
EntryCount func (v *LogViewer) EntryCount() int EntryCount returns total entry count
Error func (v *LogViewer) Error(message string) *LogViewer Error logs an error message
FilteredCount func (v *LogViewer) FilteredCount() int FilteredCount returns filtered entry count
GetEntries func (v *LogViewer) GetEntries() []LogEntry GetEntries returns all entries
GetFieldHeight func (v *LogViewer) GetFieldHeight() int GetFieldHeight returns preferred height
GetFilteredEntries func (v *LogViewer) GetFilteredEntries() []LogEntry GetFilteredEntries returns filtered entries
Info func (v *LogViewer) Info(message string) *LogViewer Info logs an info message
Log func (v *LogViewer) Log(level LogLevel, message string) *LogViewer Log adds a simple log entry
SetFilter func (v *LogViewer) SetFilter(filter LogFilter) *LogViewer SetFilter sets the log filter
SetFollow func (v *LogViewer) SetFollow(follow bool) *LogViewer SetFollow enables/disables auto-scroll
SetMaxEntries func (v *LogViewer) SetMaxEntries(max int) *LogViewer SetMaxEntries sets the maximum log entries to keep
SetMinLevel func (v *LogViewer) SetMinLevel(level LogLevel) *LogViewer SetMinLevel sets minimum log level to show
SetOnSearch func (v *LogViewer) SetOnSearch(fn func(pattern string, matches int)) *LogViewer SetOnSearch sets callback for search results
SetOnSelect func (v *LogViewer) SetOnSelect(fn func(entry LogEntry)) *LogViewer SetOnSelect sets callback for entry selection
SetSearch func (v *LogViewer) SetSearch(pattern string) *LogViewer SetSearch sets the search pattern
SetSearchRegex func (v *LogViewer) SetSearchRegex(pattern string) error SetSearchRegex sets a regex search pattern
SetShowLevel func (v *LogViewer) SetShowLevel(show bool) *LogViewer SetShowLevel enables/disables level display
SetShowSource func (v *LogViewer) SetShowSource(show bool) *LogViewer SetShowSource enables/disables source display
SetShowTimestamp func (v *LogViewer) SetShowTimestamp(show bool) *LogViewer SetShowTimestamp enables/disables timestamp display
SetTimestampFormat func (v *LogViewer) SetTimestampFormat(format string) *LogViewer SetTimestampFormat sets the timestamp format
SetWrapLines func (v *LogViewer) SetWrapLines(wrap bool) *LogViewer SetWrapLines enables/disables line wrapping
Warn func (v *LogViewer) Warn(message string) *LogViewer Warn logs a warning message

Types

type LogEntry struct LogEntry is a single log record. Fields holds structured key-value pairs (e.g., from a JSON log line); they are displayed alongside the message.
FieldTypeDescription
Timestamp time.Time
Level LogLevel
Message string
Source string Optional source/logger name
Fields map[string]string Optional structured fields
type LogFilter struct LogFilter defines filtering criteria applied to the log stream. Search and SearchRegex are mutually exclusive — SearchRegex takes precedence when set. Zero-value time fields disable time-range filtering.
FieldTypeDescription
MinLevel LogLevel
MaxLevel LogLevel
Search string
SearchRegex *regexp.Regexp
Sources []string Empty = all sources
TimeFrom time.Time
TimeTo time.Time
type LogLevel LogLevel represents log severity in ascending order (Debug < Info < Warn < Error < Fatal).
ConstantDescription
LogLevelDebug
LogLevelInfo
LogLevelWarn
LogLevelError
LogLevelFatal