Skip to content

Commit

Permalink
feat: better presentation for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jkelleyrtp committed Dec 6, 2024
1 parent a412910 commit 60fe5c5
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 25 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,12 @@ clap = { version = "4.5.7" }
askama_escape = "0.10.3"
tracing = "0.1.37"
tracing-futures = "0.2.5"
tracing-subscriber = "0.3.18"
tracing-subscriber = { version = "0.3.18", default-features = false }
toml = "0.8"
tokio = "1.40"
slab = "0.4.2"
slotmap = { version = "1.0.7", features = ["serde"] }
futures = "0.3.30"
futures-channel = "0.3.21"
futures-util = { version = "0.3", default-features = false }
rustc-hash = "1.1.0"
Expand Down Expand Up @@ -223,6 +224,8 @@ cargo-config2 = "0.1.26"
criterion = { version = "0.5" }
walrus = "0.23.2"
cargo_metadata = "0.18.1"
tracing-wasm = "0.2.1"
console_error_panic_hook = "0.1.7"

# desktop
wry = { version = "0.45.0", default-features = false }
Expand Down
6 changes: 3 additions & 3 deletions examples/fullstack-streaming/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ publish = false

[dependencies]
dioxus = { workspace = true, features = ["fullstack"] }
serde = "1.0.159"
futures = "0.3.30"
serde = { workspace = true }
futures = { workspace = true }
tokio = { workspace = true, optional = true }
futures-util.workspace = true
once_cell = "1.19.0"
once_cell = { workspace = true }

[features]
default = []
Expand Down
1 change: 1 addition & 0 deletions examples/fullstack-streaming/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub async fn test_stream() -> Result<TextStream, ServerFnError> {
tokio::spawn(async move {
loop {
tokio::time::sleep(tokio::time::Duration::from_millis(500)).await;
dioxus::logger::tracing::info!("Sending new chunk!");
let _ = tx.unbounded_send(Ok("Hello, world!".to_string()));
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ignore = "0.4.22"
env_logger = { workspace = true }
const-serialize = { workspace = true, features = ["serde"] }

tracing-subscriber = { version = "0.3.18", features = ["std", "env-filter", "json"] }
tracing-subscriber = { version = "0.3.18", features = ["std", "env-filter", "json", "registry", "fmt"] }
console-subscriber = { version = "0.3.0", optional = true }
tracing = { workspace = true }
wasm-opt = { version = "0.116.1", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion packages/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dioxus-html = { workspace = true, features = ["serialize"] }
tokio = { workspace = true, features = ["full"] }
rand = { workspace = true }
reqwest = { workspace = true }
tracing-subscriber = { workspace = true }
tracing-subscriber = { workspace = true, default-features = true }
tracing-fluent-assertions = "0.3.0"
pretty_assertions = "1.3.0"

Expand Down
1 change: 0 additions & 1 deletion packages/desktop/src/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl WebviewEdits {
self.handle_html_event(event)
}
Err(err) => {
tracing::error!("cannot decippher format of user event");
tracing::error!(
"Error parsing user_event: {:?}.Contents: {:?}, raw: {:#?}",
err,
Expand Down
14 changes: 5 additions & 9 deletions packages/logger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@ categories = ["development-tools::debugging"]


[dependencies]
dioxus-cli-config = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, default-features = false, features = [
"registry",
"std",
] }
tracing-subscriber = { workspace = true, features = ["registry", "std"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
tracing-wasm = "0.2.1"
console_error_panic_hook = "0.1.7"
tracing-wasm = { workspace = true }
console_error_panic_hook = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tracing-subscriber = { workspace = true, default-features = false, features = [
"fmt",
] }
tracing-subscriber = { workspace = true, features = [ "fmt" ] }
16 changes: 10 additions & 6 deletions packages/logger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ pub fn init(level: Level) -> Result<(), SetGlobalDefaultError> {
}

#[cfg(not(target_arch = "wasm32"))]
return {
let sub = tracing_subscriber::FmtSubscriber::builder()
.with_max_level(level)
.finish();
{
let sub = tracing_subscriber::FmtSubscriber::builder().with_max_level(level);

if !dioxus_cli_config::is_cli_enabled() {
return set_global_default(sub.finish());
}

set_global_default(sub)
};
// todo(jon): this is a small hack to clean up logging when running under the CLI
// eventually we want to emit everything as json and let the CLI manage the parsing + display
set_global_default(sub.without_time().with_target(false).finish())
}
}
6 changes: 3 additions & 3 deletions packages/signals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ rust-version = "1.79.0"
dioxus-core = { workspace = true }
generational-box = { workspace = true }
tracing = { workspace = true }
serde = { version = "1", features = ["derive"], optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
parking_lot = "0.12.1"
once_cell = "1.18.0"
once_cell = { workspace = true }
rustc-hash = { workspace = true }
futures-channel = { workspace = true }
futures-util = { workspace = true }
Expand All @@ -27,7 +27,7 @@ warnings = { workspace = true }
[dev-dependencies]
dioxus = { workspace = true }
tokio = { workspace = true, features = ["full"] }
tracing-subscriber = "0.3.17"
tracing-subscriber = { workspace = true, default-features = true }
reqwest = { workspace = true }
rand = { workspace = true }

Expand Down

0 comments on commit 60fe5c5

Please sign in to comment.