From f0dbe9fa6088c583e586a73dd485e079b836656a Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Mon, 18 Aug 2025 23:40:25 +0800 Subject: [PATCH] feat: add console-subscriber for improved logging and tracing support --- src-tauri/Cargo.lock | 205 ++++++++++++++++++++++++++++++++++++++---- src-tauri/Cargo.toml | 2 + src-tauri/src/lib.rs | 2 +- src-tauri/src/main.rs | 2 + 4 files changed, 195 insertions(+), 16 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index ce2c4104..a18aefce 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -477,7 +477,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.3.4", "bitflags 1.3.2", "bytes", "futures-util", @@ -498,6 +498,33 @@ dependencies = [ "tower-service", ] +[[package]] +name = "axum" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edca88bc138befd0323b20752846e6587272d3b03b0343c8ea28a6f819e6e71f" +dependencies = [ + "async-trait", + "axum-core 0.4.5", + "bytes", + "futures-util", + "http 1.3.1", + "http-body 1.0.1", + "http-body-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper 1.0.2", + "tower 0.5.2", + "tower-layer", + "tower-service", +] + [[package]] name = "axum-core" version = "0.3.4" @@ -515,6 +542,26 @@ dependencies = [ "tower-service", ] +[[package]] +name = "axum-core" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f2bd6146b97ae3359fa0cc6d6b376d9539582c7b4220f041a33ec24c226199" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.3.1", + "http-body 1.0.1", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 1.0.2", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.75" @@ -1053,6 +1100,7 @@ dependencies = [ "base64 0.22.1", "boa_engine", "chrono", + "console-subscriber", "criterion", "dashmap 6.1.0", "deelevate", @@ -1186,6 +1234,45 @@ dependencies = [ "crossbeam-utils", ] +[[package]] +name = "console-api" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8030735ecb0d128428b64cd379809817e620a40e5001c54465b99ec5feec2857" +dependencies = [ + "futures-core", + "prost 0.13.5", + "prost-types 0.13.5", + "tonic 0.12.3", + "tracing-core", +] + +[[package]] +name = "console-subscriber" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6539aa9c6a4cd31f4b1c040f860a1eac9aa80e7df6b05d506a6e7179936d6a01" +dependencies = [ + "console-api", + "crossbeam-channel", + "crossbeam-utils", + "futures-task", + "hdrhistogram", + "humantime", + "hyper-util", + "prost 0.13.5", + "prost-types 0.13.5", + "serde", + "serde_json", + "thread_local", + "tokio", + "tokio-stream", + "tonic 0.12.3", + "tracing", + "tracing-core", + "tracing-subscriber", +] + [[package]] name = "const-random" version = "0.1.18" @@ -1627,12 +1714,12 @@ dependencies = [ "http 0.2.12", "hyper 0.14.32", "log", - "prost-types", + "prost-types 0.12.6", "ringbuf", "thiserror 1.0.69", "tokio", "tokio-stream", - "tonic", + "tonic 0.10.2", "tonic-health", "tonic-web", "tower 0.4.13", @@ -1650,9 +1737,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c06ffa9aeb3fb248b41d4e71ab3c0aa89177afc6669459da4320b97a4c77948" dependencies = [ "bitflags 2.9.1", - "prost", - "prost-types", - "tonic", + "prost 0.12.6", + "prost-types 0.12.6", + "tonic 0.10.2", "tracing-core", ] @@ -2702,6 +2789,19 @@ dependencies = [ "foldhash", ] +[[package]] +name = "hdrhistogram" +version = "7.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "765c9198f173dd59ce26ff9f95ef0aafd0a0fe01fb9d72841bc5066a4c06511d" +dependencies = [ + "base64 0.21.7", + "byteorder", + "flate2", + "nom 7.1.3", + "num-traits", +] + [[package]] name = "headers" version = "0.4.1" @@ -2946,6 +3046,19 @@ dependencies = [ "tokio-io-timeout", ] +[[package]] +name = "hyper-timeout" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" +dependencies = [ + "hyper 1.6.0", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + [[package]] name = "hyper-tls" version = "0.6.0" @@ -5193,7 +5306,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" dependencies = [ "bytes", - "prost-derive", + "prost-derive 0.12.6", +] + +[[package]] +name = "prost" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2796faa41db3ec313a31f7624d9286acf277b52de526150b7e69f3debf891ee5" +dependencies = [ + "bytes", + "prost-derive 0.13.5", ] [[package]] @@ -5209,13 +5332,35 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "prost-derive" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d" +dependencies = [ + "anyhow", + "itertools 0.13.0", + "proc-macro2", + "quote", + "syn 2.0.104", +] + [[package]] name = "prost-types" version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" dependencies = [ - "prost", + "prost 0.12.6", +] + +[[package]] +name = "prost-types" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52c2c1bf36ddb1a1c396b3601a3cec27c2462e45f07c386894ec3ccf5332bd16" +dependencies = [ + "prost 0.13.5", ] [[package]] @@ -6901,7 +7046,7 @@ dependencies = [ "tauri", "tauri-plugin", "tokio", - "tonic", + "tonic 0.10.2", "tonic-health", "tracing", "tracing-subscriber", @@ -7608,17 +7753,47 @@ checksum = "d560933a0de61cf715926b9cac824d4c883c2c43142f787595e48280c40a1d0e" dependencies = [ "async-stream", "async-trait", - "axum", + "axum 0.6.20", "base64 0.21.7", "bytes", "h2 0.3.27", "http 0.2.12", "http-body 0.4.6", "hyper 0.14.32", - "hyper-timeout", + "hyper-timeout 0.4.1", "percent-encoding", "pin-project", - "prost", + "prost 0.12.6", + "tokio", + "tokio-stream", + "tower 0.4.13", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tonic" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" +dependencies = [ + "async-stream", + "async-trait", + "axum 0.7.9", + "base64 0.22.1", + "bytes", + "h2 0.4.11", + "http 1.3.1", + "http-body 1.0.1", + "http-body-util", + "hyper 1.6.0", + "hyper-timeout 0.5.2", + "hyper-util", + "percent-encoding", + "pin-project", + "prost 0.13.5", + "socket2 0.5.10", "tokio", "tokio-stream", "tower 0.4.13", @@ -7634,10 +7809,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f80db390246dfb46553481f6024f0082ba00178ea495dbb99e70ba9a4fafb5e1" dependencies = [ "async-stream", - "prost", + "prost 0.12.6", "tokio", "tokio-stream", - "tonic", + "tonic 0.10.2", ] [[package]] @@ -7653,7 +7828,7 @@ dependencies = [ "hyper 0.14.32", "pin-project", "tokio-stream", - "tonic", + "tonic 0.10.2", "tower-http 0.4.4", "tower-layer", "tower-service", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 2736418b..ecc119f9 100755 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -76,6 +76,7 @@ scopeguard = "1.2.0" kode-bridge = "0.2.0" dashmap = "6.1.0" tauri-plugin-notification = "2.3.0" +console-subscriber = {version = "0.4.1", optional = true} [target.'cfg(windows)'.dependencies] runas = "=1.2.0" @@ -107,6 +108,7 @@ tauri-plugin-updater = "2.9.0" default = ["custom-protocol"] custom-protocol = ["tauri/custom-protocol"] verge-dev = [] +tokio-trace = ["console-subscriber"] [profile.release] panic = "abort" diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 21b158b5..92f63ea1 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -185,7 +185,7 @@ mod app_init { .plugin(tauri_plugin_shell::init()) .plugin(tauri_plugin_deep_link::init()); - #[cfg(debug_assertions)] + #[cfg(all(debug_assertions, not(feature = "tokio-trace")))] { builder = builder.plugin(tauri_plugin_devtools::init()); } diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 293b1b22..6a088a2e 100755 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1,4 +1,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] fn main() { + #[cfg(feature = "tokio-trace")] + console_subscriber::init(); app_lib::run(); }