diff --git a/handlers/pa_volume/src/handler.rs b/handlers/pa_volume/src/handler.rs index e547549..359204c 100644 --- a/handlers/pa_volume/src/handler.rs +++ b/handlers/pa_volume/src/handler.rs @@ -138,7 +138,7 @@ fn state_matches(target: &Target, state: &PaEntityState) -> bool { TargetPredicatePattern::Regex { regex } => regex.is_match(v), } } else { - warn!("Property \"{}\" is not available for targets of type \"{}\"", &p.property, &target.kind); + log::warn!("Property \"{}\" is not available for targets of type \"{}\"", &p.property, &target.kind); false } diff --git a/handlers/playerctl/src/handler.rs b/handlers/playerctl/src/handler.rs index ab68620..c6e4289 100644 --- a/handlers/playerctl/src/handler.rs +++ b/handlers/playerctl/src/handler.rs @@ -129,7 +129,7 @@ impl PlayerctlStateWatcher { let mut g = cloned_state.write().unwrap(); *g = new_state.clone(); if cloned_new_states.send(new_state).is_err() { - warn!("No one is listening to player state changes") + log::warn!("No one is listening to player state changes") } } } @@ -211,7 +211,7 @@ pub async fn manage_button(path: KeyPath, config: ButtonConfig, mut events: broa let status = std::process::Command::new("playerctl").arg(command).status().unwrap(); if !status.success() { - error!("`playerctl {}` failed with exit code {}", command, status) + log::error!("`playerctl {}` failed with exit code {}", command, status) } } } @@ -252,7 +252,7 @@ pub async fn manage_shuffle(path: KeyPath, config: ShuffleConfig, mut events: br let status = std::process::Command::new("playerctl").args(["shuffle", new]).status().unwrap(); if !status.success() { - error!("`playerctl shuffle {}` failed with exit code {}", new, status) + log::error!("`playerctl shuffle {}` failed with exit code {}", new, status) } } } @@ -294,7 +294,7 @@ pub async fn manage_loop(path: KeyPath, config: LoopConfig, mut events: broadcas let status = std::process::Command::new("playerctl").args(["loop", new]).status().unwrap(); if !status.success() { - error!("`playerctl loop {}` failed with exit code {}", new, status) + log::error!("`playerctl loop {}` failed with exit code {}", new, status) } } } diff --git a/src/coordinator/graphics.rs b/src/coordinator/graphics.rs index 1d549c0..f890d58 100644 --- a/src/coordinator/graphics.rs +++ b/src/coordinator/graphics.rs @@ -1,7 +1,6 @@ use std::cell::RefCell; use bytes::{BufMut, Bytes, BytesMut}; -use log::error; use resvg::usvg::tiny_skia_path::PathBuilder; use rgb::RGBA; use tiny_skia::{Color, IntSize, LineCap, LineJoin, Paint, Pixmap, PremultipliedColorU8, Rect, Shader, Stroke, Transform}; @@ -28,7 +27,7 @@ pub fn render_key(context: &GraphicsContext, key_size: IntSize, state: Option<&K if let Some(icon) = &style.icon { if let Err(e) = context.icon_manager.render_icon_in(&mut pixmap, icon) { - error!("Failed to render key: {}", e); + log::error!("Failed to render key: {}", e); } } @@ -71,7 +70,7 @@ pub fn render_knob(context: &GraphicsContext, screen_size: IntSize, state: Optio if let Some(icon) = &style.icon { if let Err(e) = context.icon_manager.render_icon_in(&mut pixmap, icon) { - error!("Failed to render knob: {}", e); + log::error!("Failed to render knob: {}", e); } } diff --git a/src/coordinator/io_worker.rs b/src/coordinator/io_worker.rs index a7c024f..be7e7f1 100644 --- a/src/coordinator/io_worker.rs +++ b/src/coordinator/io_worker.rs @@ -3,7 +3,6 @@ use std::path::Path; use std::sync::Arc; use enum_ordinalize::Ordinalize; -use log::{error, trace}; use resvg::usvg::tiny_skia_path::IntSize; use rgb::RGB8; use tokio::sync::broadcast; @@ -86,15 +85,15 @@ pub fn do_io_work(context: IoWorkerContext, commands_receiver: flume::Receiver bool { - trace!("Handling event: {:?}", &event); + log::trace!("Handling event: {:?}", &event); let send_key_event = |path: KeyPath, event: KeyEvent| { - trace!("Sending key event ({}): {:?}", &path, &event); + log::trace!("Sending key event ({}): {:?}", &path, &event); context.events_sender.send(HandlerEvent::Key { path, event }).unwrap(); }; let send_knob_event = |path: KnobPath, event: KnobEvent| { - trace!("Sending knob event ({:?}): {:?}", &path, &event); + log::trace!("Sending knob event ({:?}): {:?}", &path, &event); context.events_sender.send(HandlerEvent::Knob { path, event }).unwrap(); }; @@ -200,7 +199,7 @@ fn handle_event(context: &IoWorkerContext, state: &mut State, event: LoupedeckEv } fn handle_command(context: &IoWorkerContext, state: &mut State, command: HandlerCommand) { - trace!("Handling command: {:?}", &command); + log::trace!("Handling command: {:?}", &command); match command { HandlerCommand::SetActivePages { key_page_id, knob_page_id } => { @@ -244,7 +243,7 @@ fn handle_command(context: &IoWorkerContext, state: &mut State, command: Handler HandlerCommand::SetKnobValue { path, value } => { if let Some(v) = value { if !(0.0..=1.0).contains(&v) { - error!("Received SetKnobValue with an out-of-range value: {}", v); + log::error!("Received SetKnobValue with an out-of-range value: {}", v); return; } } diff --git a/src/coordinator/mod.rs b/src/coordinator/mod.rs index df9db10..579cddc 100644 --- a/src/coordinator/mod.rs +++ b/src/coordinator/mod.rs @@ -4,7 +4,6 @@ use std::thread; use color_eyre::eyre::{ContextCompat, WrapErr}; use color_eyre::Result; -use log::info; use nanoid::nanoid; use tokio::sync::broadcast; @@ -28,11 +27,11 @@ pub mod state; pub async fn start(config_directory: &Path, config: Config) -> Result<()> { let config = Arc::new(config); - info!("Discovering devices…"); + log::info!("Discovering devices…"); let available_devices = LoupedeckDevice::discover()?; let available_device = available_devices.first().wrap_err("No device connected.")?; - info!("Found {} device(s).", available_devices.len()); + log::info!("Found {} device(s).", available_devices.len()); let (commands_sender, commands_receiver) = flume::bounded::(5); let events_sender = broadcast::Sender::::new(5); @@ -91,11 +90,11 @@ pub async fn start(config_directory: &Path, config: Config) -> Result<()> { }; if let Some(mqtt_config) = &config.mqtt { - info!("Initializing MQTT client…"); + log::info!("Initializing MQTT client…"); start_mqtt_client(mqtt_config, &handler_hosts_config, commands_sender.clone(), events_sender.subscribe()).await; } - info!("Initializing handler processes…"); + log::info!("Initializing handler processes…"); handler_runner::start( get_default_host_id(), @@ -106,9 +105,9 @@ pub async fn start(config_directory: &Path, config: Config) -> Result<()> { ) .await?; - info!("Connecting to the device…"); + log::info!("Connecting to the device…"); let device = available_device.connect().wrap_err("Connecting to the device failed.")?; - info!("Connected."); + log::info!("Connected."); device.set_brightness(0.5); device.vibrate(VibrationPattern::RiseFall); @@ -122,7 +121,7 @@ pub async fn start(config_directory: &Path, config: Config) -> Result<()> { }) .wrap_err("Could not spawn the worker thread")?; - info!("Ready."); + log::info!("Ready."); io_worker_thread.join().unwrap(); Ok(()) diff --git a/src/coordinator/mqtt.rs b/src/coordinator/mqtt.rs index ab907eb..8ddc994 100644 --- a/src/coordinator/mqtt.rs +++ b/src/coordinator/mqtt.rs @@ -1,7 +1,6 @@ use std::str::FromStr; use std::time::Duration; -use log::{error, info}; use rumqttc::{Event, Incoming, LastWill, MqttOptions, QoS}; use tokio::sync::broadcast; @@ -88,10 +87,10 @@ pub async fn start_mqtt_client( match event_loop.poll().await { Err(error) => { if is_first_try { - error!("MQTT connection failed (retrying in the background): {error}"); + log::error!("MQTT connection failed (retrying in the background): {error}"); is_first_try = false; } else if is_connected { - error!("MQTT connection lost: {error}"); + log::error!("MQTT connection lost: {error}"); } is_connected = false; @@ -99,7 +98,7 @@ pub async fn start_mqtt_client( } Ok(Event::Incoming(event)) => match event { Incoming::ConnAck(_) => { - info!("MQTT connection established."); + log::info!("MQTT connection established."); is_connected = true; is_first_try = false; diff --git a/src/coordinator/state.rs b/src/coordinator/state.rs index fe96056..1e70ec5 100644 --- a/src/coordinator/state.rs +++ b/src/coordinator/state.rs @@ -1,7 +1,6 @@ use std::collections::{HashMap, HashSet}; use enum_map::EnumMap; -use log::error; use deckster_shared::path::{KeyPath, KeyPosition, KnobPath, KnobPosition}; use deckster_shared::state::{Key, Knob}; @@ -75,9 +74,9 @@ impl State { pub fn mutate_key_for_command(&mut self, command_name: &'static str, path: &KeyPath, mutator: impl FnOnce(&mut Key) -> R) -> Option { match self.key_pages_by_id.get_mut(&path.page_id) { - None => error!("Received {} command with invalid path.page_id: {}", command_name, &path.page_id), + None => log::error!("Received {} command with invalid path.page_id: {}", command_name, &path.page_id), Some(key_page) => match key_page.keys_by_position.get_mut(&path.position) { - None => error!("Received {} command with invalid path.position: {}", command_name, &path.position), + None => log::error!("Received {} command with invalid path.position: {}", command_name, &path.position), Some(key) => return Some(mutator(key)), }, } @@ -87,7 +86,7 @@ impl State { pub fn mutate_knob_for_command(&mut self, command_name: &'static str, path: &KnobPath, mutator: impl FnOnce(&mut Knob) -> R) -> Option { match self.knob_pages_by_id.get_mut(&path.page_id) { - None => error!("Received {} command with invalid path.page_id: {}", command_name, &path.page_id), + None => log::error!("Received {} command with invalid path.page_id: {}", command_name, &path.page_id), Some(knob_page) => return Some(mutator(&mut knob_page.knobs_by_position[path.position])), } diff --git a/src/handler_host/mod.rs b/src/handler_host/mod.rs index d0d30dd..5cf0035 100644 --- a/src/handler_host/mod.rs +++ b/src/handler_host/mod.rs @@ -1,7 +1,6 @@ use std::path::Path; use color_eyre::Result; -use log::{info, trace, warn}; use tokio::sync::{broadcast, mpsc}; use deckster_shared::handler_communication::{HandlerCommand, HandlerEvent}; @@ -16,10 +15,10 @@ pub async fn start(config_directory: &Path, config: Config) -> Result<()> { let (handler_hosts_config_sender, mut handler_hosts_config_receiver) = mpsc::channel(1); let events_sender = broadcast::Sender::::new(5); - info!("Initializing MQTT client…"); + log::info!("Initializing MQTT client…"); mqtt::start_mqtt_client(&config.mqtt, handler_hosts_config_sender, commands_receiver, events_sender.clone()).await; - info!("Waiting for initial configuration…"); + log::info!("Waiting for initial configuration…"); let mut is_running = false; @@ -27,7 +26,7 @@ pub async fn start(config_directory: &Path, config: Config) -> Result<()> { match handler_hosts_config { None => { if is_running { - info!("Stopping handlers…"); + log::info!("Stopping handlers…"); events_sender.send(HandlerEvent::Stop).ok(); // only fails when all handlers are already stopped. } @@ -35,14 +34,14 @@ pub async fn start(config_directory: &Path, config: Config) -> Result<()> { } Some(handler_hosts_config) => { if is_running { - warn!("A new configuration was received before the old one was cleared."); + log::warn!("A new configuration was received before the old one was cleared."); events_sender.send(HandlerEvent::Stop).ok(); // only fails when all handlers are already stopped. } is_running = true; - info!("Received new configuration. Starting handlers…"); - trace!("New configuration: {handler_hosts_config:#?}"); + log::info!("Received new configuration. Starting handlers…"); + log::trace!("New configuration: {handler_hosts_config:#?}"); handler_runner::start( config.host_id.clone(), diff --git a/src/handler_host/mqtt.rs b/src/handler_host/mqtt.rs index 963aa1a..269d3bb 100644 --- a/src/handler_host/mqtt.rs +++ b/src/handler_host/mqtt.rs @@ -1,7 +1,6 @@ use std::str::FromStr; use std::time::Duration; -use log::{error, info}; use rumqttc::{Event, Incoming, MqttOptions, QoS}; use tokio::sync::{broadcast, mpsc}; @@ -41,10 +40,10 @@ pub async fn start_mqtt_client( match event_loop.poll().await { Err(error) => { if is_first_try { - error!("MQTT connection failed (retrying in the background): {error}"); + log::error!("MQTT connection failed (retrying in the background): {error}"); is_first_try = false; } else if is_connected { - error!("MQTT connection lost: {error}"); + log::error!("MQTT connection lost: {error}"); handler_hosts_config_sender .send(None) .await @@ -57,7 +56,7 @@ pub async fn start_mqtt_client( Ok(Event::Incoming(event)) => { match event { Incoming::ConnAck(_) => { - info!("MQTT connection established."); + log::info!("MQTT connection established."); is_connected = true; is_first_try = false; diff --git a/src/handler_runner.rs b/src/handler_runner.rs index cdb0388..c24dd95 100644 --- a/src/handler_runner.rs +++ b/src/handler_runner.rs @@ -9,7 +9,6 @@ use color_eyre::eyre::{eyre, WrapErr}; use color_eyre::Result; use is_executable::IsExecutable; use itertools::Itertools; -use log::{debug, error, warn}; use serde::{Deserialize, Serialize}; use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; use tokio::process::{ChildStdin, Command}; @@ -127,7 +126,7 @@ pub async fn start( match result { Err(error) => { - error!("Failed to forward an event to its handler: {error}") + log::error!("Failed to forward an event to its handler: {error}") } Ok(should_continue) => { if !should_continue { @@ -155,7 +154,7 @@ async fn start_handler( handler_config_by_knob_path_by_handler_name.remove(&handler_name), ) { (None, None) => { - warn!("Handler '{handler_name}' is not used by any key or knob."); + log::warn!("Handler '{handler_name}' is not used by any key or knob."); return Ok(()); } (a, b) => (a.unwrap_or_default(), b.unwrap_or_default()), @@ -224,11 +223,11 @@ async fn start_handler( if !should_stop.load(Ordering::Relaxed) { match exit_status.code() { - None => error!("The '{handler_name}' handler was unexpectedly terminated by a signal."), - Some(code) => error!("The '{handler_name}' handler exited unexpectedly with status code {code}"), + None => log::error!("The '{handler_name}' handler was unexpectedly terminated by a signal."), + Some(code) => log::error!("The '{handler_name}' handler exited unexpectedly with status code {code}"), } } else { - debug!("The '{handler_name}' handler exited: {exit_status:#?}"); + log::debug!("The '{handler_name}' handler exited: {exit_status:#?}"); } });