Skip to main content

Module logging

Module logging 

Source
Expand description

LSP logging facade – the producer side of the *lsp* / *lsp:<server>* / *lsp:<server>:trace* buffer views (Phase 4.1.f).

§Inspiration

emacs’s lsp-mode puts subsystem events in *lsp-log* and per-server stderr in *<server> stderr*. eglot’s *EGLOT (project/lang) events* captures the JSON-RPC trace when toggled. lattice combines both ideas under everything-is-a-buffer (§5.9):

  • Subsystem buffer (*lsp*) – supervisor events (spawn / handshake / crash / restart) plus cross-server messages.
  • Per-server buffer (*lsp:<server-id>*) – stderr + window/logMessage + window/showMessage + lifecycle for one server.
  • Per-server trace (*lsp:<server-id>:trace*) – every inbound / outbound JSON-RPC message. Off by default; toggle with :lsp-trace <server>.

§Producer / consumer split

This module is the producer: actors and the supervisor emit LogRecords through LspLogger::log. Records land in bounded LogRings held inside the logger.

The consumer – buffer-backed log views in lattice-ui-tui – snapshots a ring on demand via LspLogger::snapshot_global / [LspLogger::snapshot_server] and renders the records. Auto-scroll-to-tail and live tail-follow are buffer-side concerns; the producer just appends.

§Tracing crate fan-out

Every LspLogger::log call also emits a tracing::* event at the matching level so users who prefer RUST_LOG=lattice_lsp=debug ./lattice still see everything. The two paths are independent: the in-memory rings survive even when no tracing subscriber is installed, and tracing users see the same events whether or not the buffer views are open.

Structs§

InstanceKey
Composite key for the per-instance log ring – the (server_id, workspace_root) pair that the supervisor uses to key actors. Two rust-analyzer processes against different workspaces stay distinct in the logger and in the buffer name. Cheap to clone (two Arcs).
LogRecord
One log entry. Cheap to clone (Arc<str> for server id, Arc<Path> for workspace; the message is a plain String).
LogRing
Bounded ring of log records. Append-only; oldest is evicted when capacity is reached.
LspLogger
Producer-side log facade. One per LSP subsystem; each actor gets a clone (cheap – internal state is Arc<Mutex<...>>).

Enums§

LogLevel
Severity levels. Ordered low-to-high so the derived PartialOrd matches “Error > Warn > … > Trace”. Per-server min level filters records BELOW it (i.e. level < min drops; level >= min keeps).
LogSource
Where a log record originated.

Functions§

format_log_event_line
Format one log record line for append to a synthetic LSP log buffer (B’.3: hoisted out of lattice_ui_tui::app::lsp_log_buffers so log modes in this crate can reuse it from a tokio task). Shape: HH:MM:SS.mmm [<server>] <level> <source>: <message>. Trailing newline is the caller’s responsibility (the drain batches many records into one buffer-append).
level_tag
Compact severity tag for LspLogPushed. Mirrors LogSource::tag’s shape for the level discriminator.

Type Aliases§

LogEventPublisher
Closure invoked on every successful append. Wired by the App (or test harness) to publish LspLogPushed onto the runtime event bus via EventBus::publish_typed, which lets log buffers refresh live as records arrive. Optional: LspLogger::with_defaults() starts with no publisher; set_event_publisher installs one.