From 37cf9c94331e4d8c0a81403b02d7c2bd1d82aaf5 Mon Sep 17 00:00:00 2001 From: John Lewis Date: Mon, 29 Jan 2024 15:58:10 -0600 Subject: [PATCH] added tracing --- engine/Cargo.lock | 66 ++++++++++++++++++++++++++++++++ engine/Cargo.toml | 2 + engine/crates/engine/Cargo.toml | 2 + engine/crates/engine/src/main.rs | 10 ++++- 4 files changed, 79 insertions(+), 1 deletion(-) diff --git a/engine/Cargo.lock b/engine/Cargo.lock index 9ddee74..4fd2835 100644 --- a/engine/Cargo.lock +++ b/engine/Cargo.lock @@ -165,6 +165,8 @@ dependencies = [ "axum", "color-eyre", "tokio", + "tracing", + "tracing-subscriber", ] [[package]] @@ -445,6 +447,16 @@ dependencies = [ "windows-sys", ] +[[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_cpus" version = "1.16.0" @@ -470,6 +482,12 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "owo-colors" version = "3.5.0" @@ -791,9 +809,21 @@ checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "log", "pin-project-lite", + "tracing-attributes", "tracing-core", ] +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tracing-core" version = "0.1.32" @@ -814,15 +844,29 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + [[package]] name = "tracing-subscriber" version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" dependencies = [ + "nu-ansi-term", "sharded-slab", + "smallvec", "thread_local", "tracing-core", + "tracing-log", ] [[package]] @@ -843,6 +887,28 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/engine/Cargo.toml b/engine/Cargo.toml index f278d46..274afee 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -7,3 +7,5 @@ members = ["crates/*"] tokio = { version = "1.35.1", features = ["full"] } color-eyre = "0.6.2" axum = "0.7.4" +tracing = "0.1.40" +tracing-subscriber = "0.3.18" diff --git a/engine/crates/engine/Cargo.toml b/engine/crates/engine/Cargo.toml index 4abcf77..afd6b8e 100644 --- a/engine/crates/engine/Cargo.toml +++ b/engine/crates/engine/Cargo.toml @@ -9,3 +9,5 @@ edition = "2021" tokio.workspace = true color-eyre.workspace = true axum.workspace = true +tracing.workspace = true +tracing-subscriber.workspace = true diff --git a/engine/crates/engine/src/main.rs b/engine/crates/engine/src/main.rs index 9f7d9dc..09a4b10 100644 --- a/engine/crates/engine/src/main.rs +++ b/engine/crates/engine/src/main.rs @@ -1,14 +1,22 @@ use axum::{routing::get, Router}; use color_eyre::eyre::Result; +use tracing::info; #[tokio::main] async fn main() -> Result<()> { color_eyre::install()?; + let subscriber = tracing_subscriber::fmt().finish(); + tracing::subscriber::set_global_default(subscriber)?; let app = Router::new().route("/", get(|| async { "Hello, World!" })); // run our app with hyper, listening globally on port 3000 - let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await?; + let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_string()); + let host = std::env::var("HOST").unwrap_or_else(|_| "0.0.0.0".to_string()); + let address = format!("{}:{}", host, port); + let listener = tokio::net::TcpListener::bind(&address).await?; + + info!("Listening on {}", address); axum::serve(listener, app).await?; Ok(())