Prefix all log macros with log::

This commit is contained in:
Moritz Ruth 2024-03-01 00:16:09 +01:00
parent 6c284b6365
commit 1ced4381b8
Signed by: moritzruth
GPG key ID: C9BBAB79405EE56D
10 changed files with 39 additions and 47 deletions

View file

@ -138,7 +138,7 @@ fn state_matches(target: &Target, state: &PaEntityState) -> bool {
TargetPredicatePattern::Regex { regex } => regex.is_match(v), TargetPredicatePattern::Regex { regex } => regex.is_match(v),
} }
} else { } 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 false
} }

View file

@ -129,7 +129,7 @@ impl<S: Clone + Debug + Send + Sync + 'static> PlayerctlStateWatcher<S> {
let mut g = cloned_state.write().unwrap(); let mut g = cloned_state.write().unwrap();
*g = new_state.clone(); *g = new_state.clone();
if cloned_new_states.send(new_state).is_err() { 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(); let status = std::process::Command::new("playerctl").arg(command).status().unwrap();
if !status.success() { 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(); let status = std::process::Command::new("playerctl").args(["shuffle", new]).status().unwrap();
if !status.success() { 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(); let status = std::process::Command::new("playerctl").args(["loop", new]).status().unwrap();
if !status.success() { if !status.success() {
error!("`playerctl loop {}` failed with exit code {}", new, status) log::error!("`playerctl loop {}` failed with exit code {}", new, status)
} }
} }
} }

View file

@ -1,7 +1,6 @@
use std::cell::RefCell; use std::cell::RefCell;
use bytes::{BufMut, Bytes, BytesMut}; use bytes::{BufMut, Bytes, BytesMut};
use log::error;
use resvg::usvg::tiny_skia_path::PathBuilder; use resvg::usvg::tiny_skia_path::PathBuilder;
use rgb::RGBA; use rgb::RGBA;
use tiny_skia::{Color, IntSize, LineCap, LineJoin, Paint, Pixmap, PremultipliedColorU8, Rect, Shader, Stroke, Transform}; 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 Some(icon) = &style.icon {
if let Err(e) = context.icon_manager.render_icon_in(&mut pixmap, 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 Some(icon) = &style.icon {
if let Err(e) = context.icon_manager.render_icon_in(&mut pixmap, 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);
} }
} }

View file

@ -3,7 +3,6 @@ use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
use enum_ordinalize::Ordinalize; use enum_ordinalize::Ordinalize;
use log::{error, trace};
use resvg::usvg::tiny_skia_path::IntSize; use resvg::usvg::tiny_skia_path::IntSize;
use rgb::RGB8; use rgb::RGB8;
use tokio::sync::broadcast; use tokio::sync::broadcast;
@ -86,15 +85,15 @@ pub fn do_io_work(context: IoWorkerContext, commands_receiver: flume::Receiver<H
} }
fn handle_event(context: &IoWorkerContext, state: &mut State, event: LoupedeckEvent) -> bool { fn handle_event(context: &IoWorkerContext, state: &mut State, event: LoupedeckEvent) -> bool {
trace!("Handling event: {:?}", &event); log::trace!("Handling event: {:?}", &event);
let send_key_event = |path: KeyPath, event: KeyEvent| { 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(); context.events_sender.send(HandlerEvent::Key { path, event }).unwrap();
}; };
let send_knob_event = |path: KnobPath, event: KnobEvent| { 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(); 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) { fn handle_command(context: &IoWorkerContext, state: &mut State, command: HandlerCommand) {
trace!("Handling command: {:?}", &command); log::trace!("Handling command: {:?}", &command);
match command { match command {
HandlerCommand::SetActivePages { key_page_id, knob_page_id } => { 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 } => { HandlerCommand::SetKnobValue { path, value } => {
if let Some(v) = value { if let Some(v) = value {
if !(0.0..=1.0).contains(&v) { 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; return;
} }
} }

View file

@ -4,7 +4,6 @@ use std::thread;
use color_eyre::eyre::{ContextCompat, WrapErr}; use color_eyre::eyre::{ContextCompat, WrapErr};
use color_eyre::Result; use color_eyre::Result;
use log::info;
use nanoid::nanoid; use nanoid::nanoid;
use tokio::sync::broadcast; use tokio::sync::broadcast;
@ -28,11 +27,11 @@ pub mod state;
pub async fn start(config_directory: &Path, config: Config) -> Result<()> { pub async fn start(config_directory: &Path, config: Config) -> Result<()> {
let config = Arc::new(config); let config = Arc::new(config);
info!("Discovering devices…"); log::info!("Discovering devices…");
let available_devices = LoupedeckDevice::discover()?; let available_devices = LoupedeckDevice::discover()?;
let available_device = available_devices.first().wrap_err("No device connected.")?; 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::<HandlerCommand>(5); let (commands_sender, commands_receiver) = flume::bounded::<HandlerCommand>(5);
let events_sender = broadcast::Sender::<HandlerEvent>::new(5); let events_sender = broadcast::Sender::<HandlerEvent>::new(5);
@ -91,11 +90,11 @@ pub async fn start(config_directory: &Path, config: Config) -> Result<()> {
}; };
if let Some(mqtt_config) = &config.mqtt { 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; 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( handler_runner::start(
get_default_host_id(), get_default_host_id(),
@ -106,9 +105,9 @@ pub async fn start(config_directory: &Path, config: Config) -> Result<()> {
) )
.await?; .await?;
info!("Connecting to the device…"); log::info!("Connecting to the device…");
let device = available_device.connect().wrap_err("Connecting to the device failed.")?; let device = available_device.connect().wrap_err("Connecting to the device failed.")?;
info!("Connected."); log::info!("Connected.");
device.set_brightness(0.5); device.set_brightness(0.5);
device.vibrate(VibrationPattern::RiseFall); 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")?; .wrap_err("Could not spawn the worker thread")?;
info!("Ready."); log::info!("Ready.");
io_worker_thread.join().unwrap(); io_worker_thread.join().unwrap();
Ok(()) Ok(())

View file

@ -1,7 +1,6 @@
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
use log::{error, info};
use rumqttc::{Event, Incoming, LastWill, MqttOptions, QoS}; use rumqttc::{Event, Incoming, LastWill, MqttOptions, QoS};
use tokio::sync::broadcast; use tokio::sync::broadcast;
@ -88,10 +87,10 @@ pub async fn start_mqtt_client(
match event_loop.poll().await { match event_loop.poll().await {
Err(error) => { Err(error) => {
if is_first_try { 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; is_first_try = false;
} else if is_connected { } else if is_connected {
error!("MQTT connection lost: {error}"); log::error!("MQTT connection lost: {error}");
} }
is_connected = false; is_connected = false;
@ -99,7 +98,7 @@ pub async fn start_mqtt_client(
} }
Ok(Event::Incoming(event)) => match event { Ok(Event::Incoming(event)) => match event {
Incoming::ConnAck(_) => { Incoming::ConnAck(_) => {
info!("MQTT connection established."); log::info!("MQTT connection established.");
is_connected = true; is_connected = true;
is_first_try = false; is_first_try = false;

View file

@ -1,7 +1,6 @@
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use enum_map::EnumMap; use enum_map::EnumMap;
use log::error;
use deckster_shared::path::{KeyPath, KeyPosition, KnobPath, KnobPosition}; use deckster_shared::path::{KeyPath, KeyPosition, KnobPath, KnobPosition};
use deckster_shared::state::{Key, Knob}; use deckster_shared::state::{Key, Knob};
@ -75,9 +74,9 @@ impl State {
pub fn mutate_key_for_command<R>(&mut self, command_name: &'static str, path: &KeyPath, mutator: impl FnOnce(&mut Key) -> R) -> Option<R> { pub fn mutate_key_for_command<R>(&mut self, command_name: &'static str, path: &KeyPath, mutator: impl FnOnce(&mut Key) -> R) -> Option<R> {
match self.key_pages_by_id.get_mut(&path.page_id) { 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) { 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)), Some(key) => return Some(mutator(key)),
}, },
} }
@ -87,7 +86,7 @@ impl State {
pub fn mutate_knob_for_command<R>(&mut self, command_name: &'static str, path: &KnobPath, mutator: impl FnOnce(&mut Knob) -> R) -> Option<R> { pub fn mutate_knob_for_command<R>(&mut self, command_name: &'static str, path: &KnobPath, mutator: impl FnOnce(&mut Knob) -> R) -> Option<R> {
match self.knob_pages_by_id.get_mut(&path.page_id) { 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])), Some(knob_page) => return Some(mutator(&mut knob_page.knobs_by_position[path.position])),
} }

View file

@ -1,7 +1,6 @@
use std::path::Path; use std::path::Path;
use color_eyre::Result; use color_eyre::Result;
use log::{info, trace, warn};
use tokio::sync::{broadcast, mpsc}; use tokio::sync::{broadcast, mpsc};
use deckster_shared::handler_communication::{HandlerCommand, HandlerEvent}; 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 (handler_hosts_config_sender, mut handler_hosts_config_receiver) = mpsc::channel(1);
let events_sender = broadcast::Sender::<HandlerEvent>::new(5); let events_sender = broadcast::Sender::<HandlerEvent>::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; 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; let mut is_running = false;
@ -27,7 +26,7 @@ pub async fn start(config_directory: &Path, config: Config) -> Result<()> {
match handler_hosts_config { match handler_hosts_config {
None => { None => {
if is_running { if is_running {
info!("Stopping handlers…"); log::info!("Stopping handlers…");
events_sender.send(HandlerEvent::Stop).ok(); // only fails when all handlers are already stopped. 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) => { Some(handler_hosts_config) => {
if is_running { 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. events_sender.send(HandlerEvent::Stop).ok(); // only fails when all handlers are already stopped.
} }
is_running = true; is_running = true;
info!("Received new configuration. Starting handlers…"); log::info!("Received new configuration. Starting handlers…");
trace!("New configuration: {handler_hosts_config:#?}"); log::trace!("New configuration: {handler_hosts_config:#?}");
handler_runner::start( handler_runner::start(
config.host_id.clone(), config.host_id.clone(),

View file

@ -1,7 +1,6 @@
use std::str::FromStr; use std::str::FromStr;
use std::time::Duration; use std::time::Duration;
use log::{error, info};
use rumqttc::{Event, Incoming, MqttOptions, QoS}; use rumqttc::{Event, Incoming, MqttOptions, QoS};
use tokio::sync::{broadcast, mpsc}; use tokio::sync::{broadcast, mpsc};
@ -41,10 +40,10 @@ pub async fn start_mqtt_client(
match event_loop.poll().await { match event_loop.poll().await {
Err(error) => { Err(error) => {
if is_first_try { 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; is_first_try = false;
} else if is_connected { } else if is_connected {
error!("MQTT connection lost: {error}"); log::error!("MQTT connection lost: {error}");
handler_hosts_config_sender handler_hosts_config_sender
.send(None) .send(None)
.await .await
@ -57,7 +56,7 @@ pub async fn start_mqtt_client(
Ok(Event::Incoming(event)) => { Ok(Event::Incoming(event)) => {
match event { match event {
Incoming::ConnAck(_) => { Incoming::ConnAck(_) => {
info!("MQTT connection established."); log::info!("MQTT connection established.");
is_connected = true; is_connected = true;
is_first_try = false; is_first_try = false;

View file

@ -9,7 +9,6 @@ use color_eyre::eyre::{eyre, WrapErr};
use color_eyre::Result; use color_eyre::Result;
use is_executable::IsExecutable; use is_executable::IsExecutable;
use itertools::Itertools; use itertools::Itertools;
use log::{debug, error, warn};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader}; use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::process::{ChildStdin, Command}; use tokio::process::{ChildStdin, Command};
@ -127,7 +126,7 @@ pub async fn start(
match result { match result {
Err(error) => { 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) => { Ok(should_continue) => {
if !should_continue { if !should_continue {
@ -155,7 +154,7 @@ async fn start_handler(
handler_config_by_knob_path_by_handler_name.remove(&handler_name), handler_config_by_knob_path_by_handler_name.remove(&handler_name),
) { ) {
(None, None) => { (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(()); return Ok(());
} }
(a, b) => (a.unwrap_or_default(), b.unwrap_or_default()), (a, b) => (a.unwrap_or_default(), b.unwrap_or_default()),
@ -224,11 +223,11 @@ async fn start_handler(
if !should_stop.load(Ordering::Relaxed) { if !should_stop.load(Ordering::Relaxed) {
match exit_status.code() { match exit_status.code() {
None => error!("The '{handler_name}' handler was unexpectedly terminated by a signal."), None => log::error!("The '{handler_name}' handler was unexpectedly terminated by a signal."),
Some(code) => error!("The '{handler_name}' handler exited unexpectedly with status code {code}"), Some(code) => log::error!("The '{handler_name}' handler exited unexpectedly with status code {code}"),
} }
} else { } else {
debug!("The '{handler_name}' handler exited: {exit_status:#?}"); log::debug!("The '{handler_name}' handler exited: {exit_status:#?}");
} }
}); });