From f7b657df1829690d83c69b88c3fab8647c18baa1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Feb 2026 19:01:19 +0000 Subject: [PATCH 1/6] Initial plan From dbf4c32fd6e68d682e1bf5800fef5d8bd0fa6fd5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Feb 2026 19:12:16 +0000 Subject: [PATCH 2/6] Use gem_tracing for device auth guard error logging Co-authored-by: gemcoder21 <104884878+gemcoder21@users.noreply.github.com> --- apps/api/src/devices/guard.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/api/src/devices/guard.rs b/apps/api/src/devices/guard.rs index a9ba4e591..b93deab96 100644 --- a/apps/api/src/devices/guard.rs +++ b/apps/api/src/devices/guard.rs @@ -1,3 +1,4 @@ +use gem_tracing::info_with_fields; use rocket::Request; use rocket::http::Status; use rocket::outcome::Outcome::{Error, Success}; @@ -31,6 +32,9 @@ fn auth_error_outcome(req: &Request<'_>, error: DeviceError, device_id: Optio Some(id) => format!("{} device_id={}", error, id), None => error.to_string(), }; + let uri = req.uri().to_string(); + let user_agent = req.headers().get_one("User-Agent").unwrap_or("unknown"); + info_with_fields!("Request guard failed", uri = uri, status = status.code, error = message, user_agent = user_agent); cache_error(req, &message); Error((status, message)) } From 823c73f4f81bcfc3eb8a7531d6c01ae571b4bd17 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Feb 2026 19:27:48 +0000 Subject: [PATCH 3/6] revert hardcoded log_level=off, plan custom log::Log bridge in gem_tracing Co-authored-by: gemcoder21 <104884878+gemcoder21@users.noreply.github.com> --- apps/api/src/main.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/api/src/main.rs b/apps/api/src/main.rs index ad5e6345d..6773dff58 100644 --- a/apps/api/src/main.rs +++ b/apps/api/src/main.rs @@ -237,6 +237,7 @@ async fn rocket_api(settings: Settings) -> Rocket { let auth_config = devices::auth_config::AuthConfig::new(settings.api.auth.enabled, settings.api.auth.tolerance, jwt_config); let rocket = rocket::build() + .configure(("log_level", "off")) .manage(auth_config) .manage(database) .manage(Mutex::new(fiat_quotes_client)) @@ -275,6 +276,7 @@ async fn rocket_ws_prices(settings: Settings) -> Rocket { redis_url: settings.redis.url.clone(), }; rocket::build() + .configure(("log_level", "off")) .manage(Arc::new(Mutex::new(price_client))) .manage(Arc::new(price_observer_config)) .mount("/", routes![websocket_prices::ws_health]) @@ -297,6 +299,7 @@ async fn rocket_ws_stream(settings: Settings) -> Rocket { let auth_config = devices::auth_config::AuthConfig::new(settings.api.auth.enabled, settings.api.auth.tolerance, jwt_config); rocket::build() + .configure(("log_level", "off")) .manage(auth_config) .manage(database) .manage(Arc::new(Mutex::new(price_client))) From 94b455b3aa5cda200e05882bb7b380db576c9ae4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 28 Feb 2026 19:36:39 +0000 Subject: [PATCH 4/6] Bridge Rocket log crate events to gem_tracing via GemLogger; configurable via ROCKET_LOG_LEVEL env var Co-authored-by: gemcoder21 <104884878+gemcoder21@users.noreply.github.com> --- Cargo.lock | 1 + apps/api/src/main.rs | 5 ++--- crates/tracing/Cargo.toml | 1 + crates/tracing/src/lib.rs | 40 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ec7bdaa45..58294ba99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3362,6 +3362,7 @@ dependencies = [ name = "gem_tracing" version = "1.0.0" dependencies = [ + "log", "tracing", "tracing-subscriber", ] diff --git a/apps/api/src/main.rs b/apps/api/src/main.rs index 6773dff58..b950ea8d5 100644 --- a/apps/api/src/main.rs +++ b/apps/api/src/main.rs @@ -237,7 +237,6 @@ async fn rocket_api(settings: Settings) -> Rocket { let auth_config = devices::auth_config::AuthConfig::new(settings.api.auth.enabled, settings.api.auth.tolerance, jwt_config); let rocket = rocket::build() - .configure(("log_level", "off")) .manage(auth_config) .manage(database) .manage(Mutex::new(fiat_quotes_client)) @@ -276,7 +275,6 @@ async fn rocket_ws_prices(settings: Settings) -> Rocket { redis_url: settings.redis.url.clone(), }; rocket::build() - .configure(("log_level", "off")) .manage(Arc::new(Mutex::new(price_client))) .manage(Arc::new(price_observer_config)) .mount("/", routes![websocket_prices::ws_health]) @@ -299,7 +297,6 @@ async fn rocket_ws_stream(settings: Settings) -> Rocket { let auth_config = devices::auth_config::AuthConfig::new(settings.api.auth.enabled, settings.api.auth.tolerance, jwt_config); rocket::build() - .configure(("log_level", "off")) .manage(auth_config) .manage(database) .manage(Arc::new(Mutex::new(price_client))) @@ -323,6 +320,8 @@ async fn main() { println!("api start service: {}", service.as_ref()); + gem_tracing::init(); + let rocket = match service { APIService::Api => rocket_api(settings).await, APIService::WebsocketPrices => rocket_ws_prices(settings).await, diff --git a/crates/tracing/Cargo.toml b/crates/tracing/Cargo.toml index a3a792299..e85c84b84 100644 --- a/crates/tracing/Cargo.toml +++ b/crates/tracing/Cargo.toml @@ -6,3 +6,4 @@ edition = { workspace = true } [dependencies] tracing = { version = "0.1.44" } tracing-subscriber = { version = "0.3.22" } +log = { version = "0.4" } diff --git a/crates/tracing/src/lib.rs b/crates/tracing/src/lib.rs index 054d99278..be0d27f7f 100644 --- a/crates/tracing/src/lib.rs +++ b/crates/tracing/src/lib.rs @@ -8,6 +8,46 @@ pub fn get_subscriber() -> Arc { TRACING_SUBSCRIBER.get_or_init(|| Arc::new(tracing_subscriber::fmt().with_target(false).finish())).clone() } +struct GemLogger; + +impl log::Log for GemLogger { + fn enabled(&self, metadata: &log::Metadata<'_>) -> bool { + metadata.level() <= log::max_level() + } + + fn log(&self, record: &log::Record<'_>) { + if !self.enabled(record.metadata()) { + return; + } + let subscriber = get_subscriber(); + let message = record.args().to_string(); + tracing::subscriber::with_default(subscriber, || match record.level() { + log::Level::Error => tracing::error!("{}", message), + log::Level::Warn => tracing::warn!("{}", message), + log::Level::Info => tracing::info!("{}", message), + log::Level::Debug => tracing::debug!("{}", message), + log::Level::Trace => tracing::trace!("{}", message), + }); + } + + fn flush(&self) {} +} + +/// Initializes gem_tracing as the global `log` backend. +/// Log level is read from the `ROCKET_LOG_LEVEL` environment variable +/// (values: `off`, `critical`, `normal`, `debug`; default: `normal`). +/// If a global logger is already registered the call is a no-op. +pub fn init() { + let level_filter = match std::env::var("ROCKET_LOG_LEVEL").as_deref() { + Ok("off") => log::LevelFilter::Off, + Ok("critical") => log::LevelFilter::Warn, + Ok("debug") => log::LevelFilter::Trace, + _ => log::LevelFilter::Info, + }; + let _ = log::set_boxed_logger(Box::new(GemLogger)); + log::set_max_level(level_filter); +} + pub fn human_duration(duration: Duration) -> String { if duration.is_zero() { return "0s".to_string(); From 068caa37d62ad07d2359fc283d973e8e18a97f72 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 2 Mar 2026 20:47:52 +0000 Subject: [PATCH 5/6] Add gem_tracing::init() to dynode main to route Rocket logs through gem_tracing Co-authored-by: gemcoder21 <104884878+gemcoder21@users.noreply.github.com> --- apps/dynode/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/dynode/src/main.rs b/apps/dynode/src/main.rs index e21d18f92..7608ed558 100644 --- a/apps/dynode/src/main.rs +++ b/apps/dynode/src/main.rs @@ -130,6 +130,7 @@ fn resolve_chain(path: &str) -> Option { #[rocket::main] async fn main() -> Result<(), Box> { + gem_tracing::init(); let (config, chains) = load_config()?; let node_address = IpAddr::from_str(config.address.as_str())?; From 3b0ae319aaf46353aa7b7c07bc0cca67252b046b Mon Sep 17 00:00:00 2001 From: gemcoder21 <104884878+gemcoder21@users.noreply.github.com> Date: Wed, 4 Mar 2026 22:33:49 +0000 Subject: [PATCH 6/6] Update crates/tracing/Cargo.toml --- crates/tracing/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/tracing/Cargo.toml b/crates/tracing/Cargo.toml index e85c84b84..5e70949d2 100644 --- a/crates/tracing/Cargo.toml +++ b/crates/tracing/Cargo.toml @@ -6,4 +6,4 @@ edition = { workspace = true } [dependencies] tracing = { version = "0.1.44" } tracing-subscriber = { version = "0.3.22" } -log = { version = "0.4" } +log = { version = "log = "0.4.29"" }