Skip to content

Switch SSR examples from wasm-logger to tracing-web#4054

Open
Copilot wants to merge 3 commits intomasterfrom
copilot/configure-ssr-examples-tracing-web
Open

Switch SSR examples from wasm-logger to tracing-web#4054
Copilot wants to merge 3 commits intomasterfrom
copilot/configure-ssr-examples-tracing-web

Conversation

Copy link

Copilot AI commented Mar 7, 2026

The two SSR examples (simple_ssr, ssr_router) used wasm-logger/log for browser-side logging. These are migrated to tracing-web + tracing-subscriber, consistent with the pattern established in yew-trunk-minimal-template.

Changes

  • Cargo.toml (workspace): Add tracing-web = "0.1" and tracing-subscriber = { version = "0.3", features = ["fmt"] } as workspace dependencies.
  • examples/simple_ssr/Cargo.toml / examples/ssr_router/Cargo.toml: Replace wasm-logger (and log) with tracing-web + tracing-subscriber in [target.'cfg(target_arch = "wasm32")'.dependencies].
  • *_hydrate.rs binaries: Replace wasm_logger::init(...) with a tracing-subscriber registry backed by MakeWebConsoleWriter.
#[cfg(target_arch = "wasm32")]
{
    let fmt_layer = tracing_subscriber::fmt::layer()
        .with_ansi(false) // Only partially supported across browsers
        .without_time()   // std::time is not available in browsers
        .with_writer(tracing_web::MakeWebConsoleWriter::new());
    use tracing_subscriber::prelude::*;
    tracing_subscriber::registry().with(fmt_layer).init();
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: Madoshakalaka <44753941+Madoshakalaka@users.noreply.github.com>
Copilot AI changed the title [WIP] Configure SSR examples to use tracing-web instead of wasm-logger Switch SSR examples from wasm-logger to tracing-web Mar 7, 2026
@Madoshakalaka Madoshakalaka marked this pull request as ready for review March 7, 2026 09:22
@Madoshakalaka Madoshakalaka added the A-examples Area: The examples label Mar 10, 2026
Copy link
Member

@WorldSEnder WorldSEnder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other examples that use wasm_logger at the moment which could switch as well. Further, this does currently not configure a the same logging level as previously, which should be easy enough to fix with tracing_subscriber's API.

@Madoshakalaka
Copy link
Member

Madoshakalaka commented Mar 17, 2026

There are other examples that use wasm_logger at the moment which could switch as well.

I specifically only did it to SSR examples, because tracing-web actually benefits there by collecting on the server side too.

our docs does mention all options so mayybe there is not enough motivation in switching all exampes?

Actually, now that I looked at the source, wasm-logger hasn't been having new commits for 6 years. Maybe that's enough motivation to adjust the docs and switch to tracing-web workspace-wide. That will belong to a different PR though.

this does currently not configure a the same logging level as previously, which should be easy enough to fix with tracing_subscriber's API.

will fix.

@Madoshakalaka
Copy link
Member

@copilot fix.

Co-authored-by: Madoshakalaka <44753941+Madoshakalaka@users.noreply.github.com>
Copy link
Author

Copilot AI commented Mar 17, 2026

@copilot fix.

Added .with_filter(tracing_subscriber::filter::LevelFilter::TRACE) to the fmt layer in both hydrate binaries, matching the previous log::Level::Trace behavior. Commit: 0cb60a8

Copy link
Member

@Madoshakalaka Madoshakalaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. I'm not sure if we should add .with_timer(UtcTime::rfc_3339()) to the examples. Opinions? @WorldSEnder

@WorldSEnder
Copy link
Member

WorldSEnder commented Mar 18, 2026

looks good. I'm not sure if we should add .with_timer(UtcTime::rfc_3339()) to the examples. Opinions?

I recommend against it in the tracing-web docs, besides missing (sys) support from std, all browsers have an option to show a timestamp next to the logged message in the debug console anyway.

@Madoshakalaka
Copy link
Member

all browsers have an option to show a timestamp next to the logged message in the debug console anyway.

TIL

worked amazing

life saver, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-examples Area: The examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants