Skip to content

Using the time crate to show time information #1

Open
@lpotthast

Description

@lpotthast

The .without_time() call mentioned in the readme is not strictly necessary.

The following setup allows timing information to be displayed by using the time crate using it's wasm-bindgen feature which enables wasm support.

In Cargo.toml, define the following dependencies:

time = { version = "0.3.23", features = ["wasm-bindgen"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["time", "local-time"] }
tracing-subscriber-wasm = "0.1.0"

And in your rust setup code, make use of the .with_timer function:

use tracing_subscriber::fmt::{fmt, time::LocalTime};
use tracing_subscriber_wasm::MakeConsoleWriter;

fmt()
        .with_writer(
            // To avoid trace events in the browser from showing their
            // JS backtrace, which is very annoying, in my opinion
            MakeConsoleWriter::default().map_trace_level_to(tracing::Level::DEBUG),
        )
        .with_timer(LocalTime::rfc_3339())
        .pretty()
        .init();

You can use different implementations. See

for more information.

Example output:

2023-07-29T15:04:26.476999936+02:00  INFO simple::app: initialize <Test>
    at examples\simple\src\app.rs:25
    in leptos_dom::components::dyn_child::<DynChild />
    in leptos_dom::Fn() -> impl IntoView

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions