Skip to main content

blockworx_web/
log.rs

1//! Where the shell's `tracing` goes: the dev-tools console, every line stamped
2//! with the time it was written, and the Performance panel, every span a
3//! timing — so a freeze reads as a gap in the log and a bar in a recording.
4//!
5//! Stamps are taken when a line is written, not when the console shows it: a
6//! blocked page shows nothing until it yields, and the lines that then appear
7//! still say when each thing happened.
8
9use tracing_subscriber::filter::{LevelFilter, Targets};
10use tracing_subscriber::fmt::format::DefaultFields;
11use tracing_subscriber::fmt::time::UtcTime;
12use tracing_subscriber::prelude::*;
13use tracing_web::{MakeWebConsoleWriter, performance_layer};
14
15/// Install the console and the Performance panel as the one subscriber: debug
16/// and up in a debug build, info and up otherwise.
17pub fn install() {
18    let level = if cfg!(debug_assertions) {
19        LevelFilter::DEBUG
20    } else {
21        LevelFilter::INFO
22    };
23    let console = tracing_subscriber::fmt::layer()
24        .with_ansi(false)
25        .with_timer(UtcTime::rfc_3339())
26        .with_writer(MakeWebConsoleWriter::new())
27        .with_filter(level);
28    // Only the app's own phases: the framework's spans would bury them, and
29    // the page keeps every timing it is given for as long as it is open.
30    let timings = performance_layer()
31        .with_details_from_fields(DefaultFields::new())
32        .with_filter(Targets::new().with_target("blockworx", level));
33    let _ = tracing_subscriber::registry()
34        .with(console)
35        .with(timings)
36        .try_init();
37}