4 releases

0.1.3 Nov 30, 2023
0.1.2 Aug 19, 2022
0.1.1 Aug 19, 2022
0.1.0 Aug 19, 2022

#67 in Debugging

Download history 6576/week @ 2024-08-04 7281/week @ 2024-08-11 9433/week @ 2024-08-18 10587/week @ 2024-08-25 11512/week @ 2024-09-01 10435/week @ 2024-09-08 9644/week @ 2024-09-15 9580/week @ 2024-09-22 10294/week @ 2024-09-29 9531/week @ 2024-10-06 10112/week @ 2024-10-13 10719/week @ 2024-10-20 8395/week @ 2024-10-27 8350/week @ 2024-11-03 8614/week @ 2024-11-10 7287/week @ 2024-11-17

33,136 downloads per month
Used in 77 crates (15 directly)

MIT/Apache

27KB
427 lines

tracing-web

A tracing compatible subscriber layer for web platforms.

Crates.io Documentation MIT licensed Apache licensed

Documentation

Overview

tracing-web can be used in conjunction with the tracing-subscriber crate to quickly install a subscriber that emits messages to the dev-tools console, and events to the Performance API. An example configuration can look like

use tracing_web::{MakeWebConsoleWriter, performance_layer};
use tracing_subscriber::fmt::format::Pretty;
use tracing_subscriber::prelude::*;

fn main() {
    let fmt_layer = tracing_subscriber::fmt::layer()
        .with_ansi(false) // Only partially supported across browsers
        .without_time()   // std::time is not available in browsers, see note below
        .with_writer(MakeWebConsoleWriter::new()); // write events to the console
    let perf_layer = performance_layer()
        .with_details_from_fields(Pretty::default());

    tracing_subscriber::registry()
        .with(fmt_layer)
        .with(perf_layer)
        .init(); // Install these as subscribers to tracing events

    todo!("write your awesome application");
}

Note: You can alternatively use .with_timer(UtcTime::rfc_3339()) with UtcTime on web targets if you enable the wasm-bindgen feature of the time crate, for example by adding the following to your Cargo.toml.

time = { version = "0.3", features = ["wasm-bindgen"] }

License

This project is dual licensed under the MIT license and the Apache license.

Dependencies

~11MB
~194K SLoC