From 932bcc94179be108062cd23dbcf9e0f5ce65ada6 Mon Sep 17 00:00:00 2001 From: Compey Date: Thu, 1 Jun 2023 20:21:41 +0530 Subject: [PATCH] debug suff --- Cargo.lock | 160 ++++++++++++++++++++++++++++++++++--------- Cargo.toml | 3 + backend/Cargo.lock | 86 +++++++++++++++-------- backend/Cargo.toml | 1 - framework/Cargo.lock | 85 +++++++++++++++-------- framework/Cargo.toml | 3 +- framework/src/lib.rs | 30 +++++--- src/main.rs | 24 +++++-- 8 files changed, 284 insertions(+), 108 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 491f847..db88099 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -56,17 +56,6 @@ dependencies = [ "opaque-debug", ] -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "android_system_properties" version = "0.1.5" @@ -82,14 +71,6 @@ version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" -[[package]] -name = "anymap" -version = "0.1.0" -source = "git+https://github.com/CompeyDev/signals-rs.git?rev=8a650a1#8a650a19813fce0dbada0e6238b9cfe7cd4660c5" -dependencies = [ - "hashbrown", -] - [[package]] name = "arrayref" version = "0.3.7" @@ -321,7 +302,6 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" name = "backend" version = "0.1.0" dependencies = [ - "anymap", "framework", "rand 0.8.5", "serde", @@ -653,10 +633,11 @@ dependencies = [ name = "framework" version = "0.1.0" dependencies = [ - "anymap", "colored", "serde", "tide", + "tide-tracing", + "tracing", ] [[package]] @@ -780,15 +761,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hermit-abi" version = "0.1.19" @@ -1021,6 +993,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -1052,9 +1034,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.1" +version = "1.17.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b" [[package]] name = "opaque-debug" @@ -1062,6 +1044,12 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "parking" version = "2.1.0" @@ -1318,7 +1306,10 @@ name = "sealz" version = "0.1.0" dependencies = [ "backend", + "once_cell", "tokio", + "tracing", + "tracing-subscriber", ] [[package]] @@ -1427,6 +1418,15 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + [[package]] name = "signal-hook" version = "0.3.15" @@ -1654,6 +1654,16 @@ dependencies = [ "syn 2.0.18", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if 1.0.0", + "once_cell", +] + [[package]] name = "tide" version = "0.16.0" @@ -1677,6 +1687,18 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tide-tracing" +version = "0.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500f567f8c4d65210e6a7c9978661cc7ad6be1dc97e32c3e88bf8f0f0599c23d" +dependencies = [ + "async-trait", + "tide", + "tracing", + "tracing-futures", +] + [[package]] name = "time" version = "0.1.45" @@ -1771,6 +1793,74 @@ dependencies = [ "syn 2.0.18", ] +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite 0.2.9", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + [[package]] name = "typenum" version = "1.16.0" @@ -1820,6 +1910,12 @@ dependencies = [ "serde", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "value-bag" version = "1.4.0" diff --git a/Cargo.toml b/Cargo.toml index 0db9921..8484dc1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,6 @@ edition = "2021" [dependencies] tokio = { version = "1.28.2", features = ["full"] } backend = { path = "./backend" } +tracing-subscriber = "0.3.17" +tracing = "0.1.37" +once_cell = "1.17.2" diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 448f4cd..4c18566 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -56,17 +56,6 @@ dependencies = [ "opaque-debug", ] -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "android_system_properties" version = "0.1.5" @@ -82,14 +71,6 @@ version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" -[[package]] -name = "anymap" -version = "0.1.0" -source = "git+https://github.com/CompeyDev/signals-rs.git?rev=8a650a1#8a650a19813fce0dbada0e6238b9cfe7cd4660c5" -dependencies = [ - "hashbrown", -] - [[package]] name = "arrayref" version = "0.3.7" @@ -321,7 +302,6 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" name = "backend" version = "0.1.0" dependencies = [ - "anymap", "framework", "rand 0.8.5", "serde", @@ -647,10 +627,11 @@ dependencies = [ name = "framework" version = "0.1.0" dependencies = [ - "anymap", "colored", "serde", "tide", + "tide-tracing", + "tracing", ] [[package]] @@ -774,15 +755,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hermit-abi" version = "0.1.19" @@ -1579,6 +1551,18 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tide-tracing" +version = "0.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500f567f8c4d65210e6a7c9978661cc7ad6be1dc97e32c3e88bf8f0f0599c23d" +dependencies = [ + "async-trait", + "tide", + "tracing", + "tracing-futures", +] + [[package]] name = "time" version = "0.1.45" @@ -1643,6 +1627,48 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite 0.2.9", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "typenum" version = "1.16.0" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 8740d5e..5474758 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -8,7 +8,6 @@ edition = "2021" [dependencies] framework = { path = "../framework" } tide = "0.16.0" -anymap = { git = "https://github.com/CompeyDev/signals-rs.git", rev = "8a650a1" } serde_json = "1.0.96" serde = { version = "1.0.163", features = ["derive"] } rand = "0.8.5" diff --git a/framework/Cargo.lock b/framework/Cargo.lock index a6c804d..bd237bf 100644 --- a/framework/Cargo.lock +++ b/framework/Cargo.lock @@ -56,17 +56,6 @@ dependencies = [ "opaque-debug", ] -[[package]] -name = "ahash" -version = "0.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", - "version_check", -] - [[package]] name = "android_system_properties" version = "0.1.5" @@ -82,14 +71,6 @@ version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" -[[package]] -name = "anymap" -version = "0.1.0" -source = "git+https://github.com/CompeyDev/signals-rs.git?rev=8a650a1#8a650a19813fce0dbada0e6238b9cfe7cd4660c5" -dependencies = [ - "hashbrown", -] - [[package]] name = "arrayref" version = "0.3.7" @@ -635,10 +616,11 @@ dependencies = [ name = "framework" version = "0.1.0" dependencies = [ - "anymap", "colored", "serde", "tide", + "tide-tracing", + "tracing", ] [[package]] @@ -762,15 +744,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "hashbrown" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" -dependencies = [ - "ahash", -] - [[package]] name = "hermit-abi" version = "0.1.19" @@ -1567,6 +1540,18 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tide-tracing" +version = "0.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500f567f8c4d65210e6a7c9978661cc7ad6be1dc97e32c3e88bf8f0f0599c23d" +dependencies = [ + "async-trait", + "tide", + "tracing", + "tracing-futures", +] + [[package]] name = "time" version = "0.1.45" @@ -1631,6 +1616,48 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite 0.2.9", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f57e3ca2a01450b1a921183a9c9cbfda207fd822cef4ccb00a65402cbba7a74" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "typenum" version = "1.16.0" diff --git a/framework/Cargo.toml b/framework/Cargo.toml index 7c49578..8e3f1b1 100644 --- a/framework/Cargo.toml +++ b/framework/Cargo.toml @@ -9,4 +9,5 @@ edition = "2021" tide = "0.16.0" serde = { version = "1.0", features = ["derive"] } colored = "2.0.0" -anymap = { git = "https://github.com/CompeyDev/signals-rs.git", rev = "8a650a1" } +tracing = "0.1.37" +tide-tracing = "0.0.12" diff --git a/framework/src/lib.rs b/framework/src/lib.rs index f65809b..7e47122 100644 --- a/framework/src/lib.rs +++ b/framework/src/lib.rs @@ -3,6 +3,7 @@ use colored::Colorize; use std::{collections::HashMap, net::SocketAddr}; use tide::{Endpoint, Result}; +use tide_tracing::TraceMiddleware; pub enum ReqType { GET, @@ -26,7 +27,7 @@ pub struct Server { impl Server { pub fn new() -> Self { Self { - instance: tide::new(), + instance: (&*tide::new().with(TraceMiddleware::new())).to_owned(), } } @@ -38,9 +39,9 @@ impl Server { ReqType::POST => route_addr.post(handler), }; - println!( - "{} :: added route {} to routes collection", - "[framework]".bold(), + tracing::info!( + target: "framework", + "added route {} to routes collection", route.blue().underline() ); } @@ -51,9 +52,9 @@ impl Server { .listen(SocketAddr::from(([127, 0, 0, 1], port))) .await .and_then(|entry| { - println!( - "{} :: {} service listening at port {}", - "[framework]".bold(), + tracing::info!( + target: "framework", + "{} service listening at port {}", scope.green(), port.to_string().yellow().bold() ); @@ -71,9 +72,9 @@ pub async fn setup_server( let mut server = Server::new(); if let Some(routes_map) = opts.bulk_routes { - println!( - "{} :: setting up server...", - "[framework_bootstrapper]".bold() + tracing::info!( + target: "framework::bootstrapper", + "setting up server...", ); for (route, handler) in routes_map { @@ -83,7 +84,14 @@ pub async fn setup_server( "GET" => ReqType::GET, "POST" => ReqType::POST, - &_ => panic!("framework::setup_serer::bulk_routes -> invalid request method type"), + &_ => { + tracing::info!( + target: "framework::bootstrapper", + "invalid route method type", + ); + + std::process::exit(1); + } }; let route = meta[1]; diff --git a/src/main.rs b/src/main.rs index bd69e1d..6131b67 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,27 @@ +use once_cell::unsync::Lazy; +use tracing::Level; + #[tokio::main] async fn main() { + let tracing_level: Lazy = Lazy::new(|| { + if cfg!(debug_assertions) { + Level::TRACE + } else { + Level::INFO + } + }); + + tracing_subscriber::fmt() + .with_max_level((&*tracing_level).to_owned()) + .init(); + let backend_service = match backend::init().await { Ok(server) => server, - Err(err) => panic!( - "[backend] :: error `{}` occurred while initializing", - err.to_string() - ), + Err(err) => { + tracing::error!(target: "backend_service", "error `{}` occurred while initializing", err.to_string()); + + std::process::exit(1); + } }; backend_service