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 {
network_tables::Value::Boolean(b) => {
if *b != *previous_gpws {
if cfg!(debug_assertions) {
println!("gpws changed from {} to {}", previous_gpws, b);
}
#[cfg(debug_assertions)]
tracing::debug!("gpws: {}", b);
app_handle
.emit_all("telemetry_gpws", b)
.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
}
Err(e) => {
if cfg!(debug_assertions) {
println!("Failed to create client: {}. Retrying in 3 seconds...", e);
}
tracing::debug!(
message = "Failed to create client. Retrying in 3 seconds...",
error = %e,
rate_limit = "3s",
);
app_handle
.emit_all("telemetry_status", "disconnected")
.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 {
Ok(subscription) => break Ok(subscription),
Err(e) => {
if cfg!(debug_assertions) {
println!("Failed to create subscription: {}", e);
}
#[cfg(debug_assertions)]
tracing::warn!("Failed to create subscription: {:?}", e);
if attempts >= 50 {
break Err(e);

View file

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