summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerguey Parkhomovsky <xindigo@gmail.com>2026-03-17 20:47:58 -0700
committerSerguey Parkhomovsky <xindigo@gmail.com>2026-03-17 20:49:23 -0700
commit06693b731e2fecefdee8db554ac1c6d113b9a819 (patch)
tree500ccd053564076c72c8409b91f37be411a5d34d
parentb42ed72e7d8f6b0a3538acdc299b1d132f8f22cb (diff)
Add tracing macros
-rw-r--r--Cargo.lock13
-rw-r--r--Cargo.toml1
-rw-r--r--src/main.rs14
3 files changed, 21 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock
index de9ee5e..6760298 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -851,6 +851,7 @@ dependencies = [
"serde_json",
"tokio",
"toml",
+ "tracing",
"tracing-subscriber",
]
@@ -1478,10 +1479,22 @@ checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
dependencies = [
"log",
"pin-project-lite",
+ "tracing-attributes",
"tracing-core",
]
[[package]]
+name = "tracing-attributes"
+version = "0.1.31"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "tracing-core"
version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index a1e51ce..3e378d7 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,4 +12,5 @@ tokio = { version = "1.49.0", features = ["full"] }
toml = "0.8"
serde_json = "1.0.149"
axum = "0.8.8"
+tracing = "0.1"
tracing-subscriber = "0.3.23"
diff --git a/src/main.rs b/src/main.rs
index d1e7a03..3c2c772 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -22,12 +22,12 @@ async fn main() {
for printer in config.printers {
match printer {
Printer::Prusa { name, host, api_key } => {
- println!("Found Prusa: {} at {}", name, host);
+ tracing::info!(name, host, "Found Prusa");
let state_clone = state.clone();
tokio::spawn(poll_prusa(name, host, api_key, state_clone));
}
Printer::Bambu { name, host, serial_number, access_code } => {
- println!("Found Bambu: {} at {}", name, host);
+ tracing::info!(name, host, "Found Bambu");
let state_clone = state.clone();
tokio::spawn(poll_bambu(name, host, serial_number, access_code, state_clone));
}
@@ -65,7 +65,7 @@ async fn poll_prusa(
}
.await;
if let Err(e) = result {
- eprintln!("Error polling Prusa printer {}: {}", name, e);
+ tracing::error!(name, error = %e, "Error polling Prusa printer");
}
tokio::time::sleep(Duration::from_secs(5)).await;
}
@@ -99,20 +99,20 @@ async fn poll_bambu(
// eventloop.poll() yields back to Tokio when there's no data
match eventloop.poll().await {
Ok(Event::Incoming(Packet::Publish(p))) => {
- println!("{:?}", &p.payload);
+ tracing::debug!(payload = ?p.payload, "Received Bambu payload");
match serde_json::from_slice::<BambuStatus>(&p.payload) {
Ok(msg) => {
let mut lock = state.lock().await;
let entry = lock.entry(name.clone()).or_default();
extract_status_from_bambu(&msg, entry);
- println!("Updated state for {}: {:?}", &name, p.payload);
+ tracing::debug!(name, payload = ?p.payload, "Updated state");
}
- Err(e) => eprintln!("Failed to deserialize BambuStatus: {}", e),
+ Err(e) => tracing::error!(error = %e, "Failed to deserialize BambuStatus"),
}
}
Ok(_) => {}
Err(e) => {
- eprintln!("MQTT error: {:?}", e);
+ tracing::error!(error = ?e, "MQTT error");
tokio::time::sleep(Duration::from_secs(5)).await; // Simple retry
}
}