summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.rs33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs
index 246cd47..74a5cca 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -11,6 +11,7 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::sync::Mutex;
use tokio::task::{Id, JoinSet};
+use tracing::{debug, error, info, warn};
type StateMap = Arc<Mutex<HashMap<String, PrinterState>>>;
@@ -32,7 +33,7 @@ async fn main() {
let args = Args::parse();
let content = fs::read_to_string(&args.config).unwrap_or_else(|e| {
- tracing::error!(path = %args.config, error = %e, "Failed to read config file");
+ error!(path = %args.config, error = %e, "Failed to read config file");
process::exit(1);
});
let config = Config::load(&content);
@@ -48,7 +49,7 @@ async fn main() {
host,
api_key,
} => {
- tracing::info!(name, host, "Found Prusa");
+ info!(name, host, "Found Prusa");
let task_name = name.clone();
let handle = tasks.spawn(poll_prusa(name, host, api_key, state));
task_names.insert(handle.id(), task_name);
@@ -59,7 +60,7 @@ async fn main() {
serial_number,
access_code,
} => {
- tracing::info!(name, host, "Found Bambu");
+ info!(name, host, "Found Bambu");
let task_name = name.clone();
let handle = tasks.spawn(poll_bambu(name, host, serial_number, access_code, state));
task_names.insert(handle.id(), task_name);
@@ -72,18 +73,18 @@ async fn main() {
match result {
Ok((id, ())) => {
let name = task_names.get(&id).map(String::as_str).unwrap_or("unknown");
- tracing::warn!(name, "Printer polling task exited unexpectedly");
+ warn!(name, "Printer polling task exited unexpectedly");
}
Err(e) => {
let name = task_names
.get(&e.id())
.map(String::as_str)
.unwrap_or("unknown");
- tracing::error!(name, error = ?e, "A printer polling task panicked");
+ error!(name, error = ?e, "A printer polling task panicked");
}
}
}
- tracing::warn!("All printer polling tasks have exited");
+ warn!("All printer polling tasks have exited");
});
let app = Router::new().route("/", get(root)).with_state(state);
@@ -91,10 +92,10 @@ async fn main() {
let listener = tokio::net::TcpListener::bind(&args.bind)
.await
.unwrap_or_else(|e| {
- tracing::error!(addr = %args.bind, error = %e, "Failed to bind to address");
+ error!(addr = %args.bind, error = %e, "Failed to bind to address");
process::exit(1);
});
- tracing::info!(addr = %args.bind, "Listening");
+ info!(addr = %args.bind, "Listening");
axum::serve(listener, app).await.unwrap();
}
@@ -123,7 +124,7 @@ async fn poll_prusa(name: String, host: String, api_key: String, state: StateMap
let client = Client::new();
loop {
if let Err(e) = fetch_prusa(&client, &name, &host, &api_key, &state).await {
- tracing::error!(name, error = %e, "Error polling Prusa printer");
+ error!(name, error = %e, "Error polling Prusa printer");
}
tokio::time::sleep(Duration::from_secs(5)).await;
}
@@ -147,7 +148,7 @@ async fn poll_bambu(
{
Ok(c) => c,
Err(e) => {
- tracing::error!(name, error = %e, "Failed to build TLS connector for Bambu printer");
+ error!(name, error = %e, "Failed to build TLS connector for Bambu printer");
return;
}
};
@@ -163,7 +164,7 @@ async fn poll_bambu(
.subscribe(format!("device/{}/report", serial_number), QoS::AtMostOnce)
.await
{
- tracing::error!(name, error = %e, "Failed to subscribe to Bambu MQTT topic");
+ error!(name, error = %e, "Failed to subscribe to Bambu MQTT topic");
}
// Send a request to push all values to us; otherwise we'll have to wait for the values to come in incremental updates.
if let Err(e) = client
@@ -182,23 +183,23 @@ async fn poll_bambu(
)
.await
{
- tracing::error!(name, error = %e, "Failed to send pushall to Bambu printer");
+ error!(name, error = %e, "Failed to send pushall to Bambu printer");
}
}
Ok(Event::Incoming(Packet::Publish(p))) => {
- tracing::debug!(payload = ?p.payload, "Received Bambu payload");
+ debug!(payload = ?p.payload, "Received Bambu payload");
match serde_json::from_slice::<BambuStatus>(&p.payload) {
Ok(msg) => {
let mut lock = state.lock().await;
lock.entry(name.clone()).or_default().update_from(&msg);
- tracing::debug!(name, payload = ?p.payload, "Updated state");
+ debug!(name, payload = ?p.payload, "Updated state");
}
- Err(e) => tracing::error!(error = %e, "Failed to deserialize BambuStatus"),
+ Err(e) => error!(error = %e, "Failed to deserialize BambuStatus"),
}
}
Ok(_) => {}
Err(e) => {
- tracing::error!(error = ?e, "MQTT error");
+ error!(error = ?e, "MQTT error");
tokio::time::sleep(Duration::from_secs(5)).await; // Simple retry
}
}