liminal-server 0.24.9

Standalone server for the liminal messaging bus
Documentation
//! SRV-041 R1: each fixed start step, logged once with its milliseconds, so a
//! slow start, liminal's own or an embedder's, says which step held it.
//!
//! Every line is on the target `liminal::boot`, with `step = "boot_step"`, the
//! step's `name` and its `elapsed_ms`. The names are fixed: a step that is
//! renamed is a step whose history no longer joins.

use std::time::Instant;

/// The tracing target every boot step line is logged on.
#[cfg(test)]
const TARGET: &str = "liminal::boot";

/// Logs the step `name` as finished, `started` being when it began.
pub fn finished(name: &'static str, started: Instant) {
    tracing::info!(
        target: "liminal::boot",
        step = "boot_step",
        name,
        elapsed_ms = u64::try_from(started.elapsed().as_millis()).unwrap_or(u64::MAX),
        "boot step finished"
    );
}

/// Runs `work` as the step `name` and logs it however it ends.
pub fn timed<T>(name: &'static str, work: impl FnOnce() -> T) -> T {
    let started = Instant::now();
    let answer = work();
    finished(name, started);
    answer
}

#[cfg(test)]
#[path = "boot_steps_tests.rs"]
mod tests;