Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: switch browser logging to tracing-web #150

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion node-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ js-sys = "0.3.64"
serde = { version = "1.0.164", features = ["derive"] }
serde_repr = "0.1"
serde-wasm-bindgen = "0.6.0"
time = { version = "0.3", features = ["wasm-bindgen"] }
tracing = "0.1.37"
tracing-wasm = "0.2.1"
tracing-subscriber = { version = "0.3.18", features = ["time"] }
tracing-web = "0.1.2"
wasm-bindgen = "0.2.88"
wasm-bindgen-futures = "0.4.37"
17 changes: 16 additions & 1 deletion node-wasm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ use std::fmt;

use celestia_node::network;
use serde_repr::{Deserialize_repr, Serialize_repr};
use tracing_subscriber::filter::LevelFilter;
use tracing_subscriber::fmt::format::Pretty;
use tracing_subscriber::fmt::time::UtcTime;
use tracing_subscriber::prelude::*;
use tracing_web::{performance_layer, MakeConsoleWriter};
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
Expand All @@ -18,7 +23,17 @@ pub enum Network {
pub fn setup_logging() {
console_error_panic_hook::set_once();

tracing_wasm::set_as_global_default();
let fmt_layer = tracing_subscriber::fmt::layer()
.with_ansi(true) // Only partially supported across browsers, but we target only chrome now
.with_timer(UtcTime::rfc_3339()) // std::time is not available in browsers
.with_writer(MakeConsoleWriter) // write events to the console
.with_filter(LevelFilter::INFO); // TODO: allow customizing the log level
let perf_layer = performance_layer().with_details_from_fields(Pretty::default());

tracing_subscriber::registry()
.with(fmt_layer)
.with(perf_layer)
.init();
}

impl From<Network> for network::Network {
Expand Down
Loading