Skip to main content

Module diagnostics

Module diagnostics 

Source
Expand description

Reusable diagnostic logging and telemetry substrate for JSONL diagnostics. Reusable diagnostic logging and telemetry substrate.

This module provides the shared infrastructure for JSONL diagnostic logging and telemetry hooks, extracted from the common patterns in crate::inspector and the demo showcase’s mouse_playground.

§Design

The core types are generic over the entry type, so each consumer defines its own DiagnosticEntry / DiagnosticEventKind while reusing the log, dispatch, and checksum infrastructure.

§Key Types

  • [DiagnosticRecord] — trait for entries that can be serialized to JSONL
  • DiagnosticLog — bounded in-memory log with optional stderr mirroring
  • TelemetryCallback — type alias for observer callbacks
  • [fnv1a_hash] — FNV-1a checksum utility for determinism verification

§Example

use ftui_widgets::diagnostics::{DiagnosticLog, DiagnosticRecord};

#[derive(Debug, Clone)]
struct MyEntry { kind: &'static str, data: u64 }

impl DiagnosticRecord for MyEntry {
    fn to_jsonl(&self) -> String {
        format!("{{\"kind\":\"{}\",\"data\":{}}}", self.kind, self.data)
    }
}

let mut log = DiagnosticLog::<MyEntry>::new();
log.record(MyEntry { kind: "test", data: 42 });
assert_eq!(log.entries().len(), 1);

Structs§

DiagnosticLog
Bounded in-memory diagnostic log with optional stderr mirroring.
DiagnosticSupport
Shared state for optional diagnostic logging plus optional telemetry hooks.

Traits§

DiagnosticHookDispatch
Trait implemented by telemetry hook collections that can observe diagnostic entries of type E.
DiagnosticRecord
Trait for diagnostic entries that can be serialized to JSONL.

Functions§

env_flag_enabled
Check an environment variable as a boolean diagnostic flag.
fnv1a_hash
Compute an FNV-1a 64-bit hash of the given byte slice.
json_string_literal
Encode a string as a JSON string literal.

Type Aliases§

TelemetryCallback
Callback type for telemetry hooks.