refactor: use tracing and attributes for debugging

This commit is contained in:
Youwen Wu 2024-03-07 13:06:42 -08:00
parent b2c77985c1
commit 34bd44691f
Signed by: youwen5
GPG key ID: 865658ED1FE61EC3
4 changed files with 15 additions and 15 deletions

View file

@ -10,9 +10,9 @@ pub fn check_triggers(
match data { match data {
network_tables::Value::Boolean(b) => { network_tables::Value::Boolean(b) => {
if *b != *previous_gpws { if *b != *previous_gpws {
if cfg!(debug_assertions) { #[cfg(debug_assertions)]
println!("gpws changed from {} to {}", previous_gpws, b); tracing::debug!("gpws: {}", b);
}
app_handle app_handle
.emit_all("telemetry_gpws", b) .emit_all("telemetry_gpws", b)
.expect("Failed to emit telemetry_gpws event"); .expect("Failed to emit telemetry_gpws event");

View file

@ -37,9 +37,11 @@ pub async fn create_client(
break client; // Exit the loop if the client is successfully created break client; // Exit the loop if the client is successfully created
} }
Err(e) => { Err(e) => {
if cfg!(debug_assertions) { tracing::debug!(
println!("Failed to create client: {}. Retrying in 3 seconds...", e); message = "Failed to create client. Retrying in 3 seconds...",
} error = %e,
rate_limit = "3s",
);
app_handle app_handle
.emit_all("telemetry_status", "disconnected") .emit_all("telemetry_status", "disconnected")
.expect("Failed to emit telemetry_status disconnected event"); .expect("Failed to emit telemetry_status disconnected event");

View file

@ -32,9 +32,8 @@ pub async fn create_subscription(client: &Client) -> Result<Subscription, networ
match subscription_attempt { match subscription_attempt {
Ok(subscription) => break Ok(subscription), Ok(subscription) => break Ok(subscription),
Err(e) => { Err(e) => {
if cfg!(debug_assertions) { #[cfg(debug_assertions)]
println!("Failed to create subscription: {}", e); tracing::warn!("Failed to create subscription: {:?}", e);
}
if attempts >= 50 { if attempts >= 50 {
break Err(e); break Err(e);

View file

@ -59,13 +59,12 @@ pub async fn subscribe_topics(
}; };
} }
if cfg!(debug_assertions) { #[cfg(debug_assertions)]
println!("{}", json_message); tracing::debug!("{}", json_message);
}
}
if cfg!(debug_assertions) {
println!("disconnected");
} }
#[cfg(debug_assertions)]
tracing::debug!("disconnected");
app_handle app_handle
.emit_all("telemetry_status", "disconnected") .emit_all("telemetry_status", "disconnected")
.expect("Failed to emit telemetry_disconnected event"); .expect("Failed to emit telemetry_disconnected event");