refactor(logging): Using more appropriate logging statements

Still probably needs some work, but that's enough for now
This commit is contained in:
quexeky
2025-01-19 18:30:16 +11:00
parent fc6bab9381
commit f183a9d1a2
8 changed files with 32 additions and 49 deletions

View File

@ -190,7 +190,7 @@ fn handle_invalid_database(
base.set_file_name(format!("drop.db.backup-{}", time.to_string()));
base
};
info!("{:?}", new_path);
info!("old database stored at: {}", new_path.to_string_lossy().to_string());
fs::rename(&db_path, &new_path).unwrap();
let db = Database::new(

View File

@ -8,7 +8,7 @@ use std::{
thread::JoinHandle,
};
use log::info;
use log::{debug, info};
use serde::Serialize;
use crate::error::application_download_error::ApplicationDownloadError;
@ -109,7 +109,7 @@ impl DownloadManager {
&self,
download: DownloadAgent,
) -> Result<(), SendError<DownloadManagerSignal>> {
info!("Adding download id {:?}", download.metadata());
info!("creating download with meta {:?}", download.metadata());
self.command_sender
.send(DownloadManagerSignal::Queue(download))?;
self.command_sender.send(DownloadManagerSignal::Go)
@ -150,12 +150,11 @@ impl DownloadManager {
.unwrap();
}
info!("moving {} to {}", current_index, new_index);
debug!("moving download at index {} to index {}", current_index, new_index);
let mut queue = self.edit();
let to_move = queue.remove(current_index).unwrap();
queue.insert(new_index, to_move);
info!("new queue: {:?}", queue);
drop(queue);
if needs_pause {

View File

@ -7,7 +7,7 @@ use std::{
thread::{spawn, JoinHandle},
};
use log::{debug, error, info};
use log::{debug, error, info, warn};
use tauri::{AppHandle, Emitter};
use crate::{
@ -179,13 +179,13 @@ impl DownloadManagerBuilder {
}
}
fn manage_queue_signal(&mut self, download_agent: DownloadAgent) {
info!("Got signal Queue");
debug!("Got signal Queue");
let meta = download_agent.metadata();
info!("Meta: {:?}", meta);
debug!("Queue metadata: {:?}", meta);
if self.download_queue.exists(meta.clone()) {
info!("Download with same ID already exists");
warn!("Download with same ID already exists");
return;
}
@ -199,9 +199,9 @@ impl DownloadManagerBuilder {
}
fn manage_go_signal(&mut self) {
info!("Got signal Go");
debug!("Got signal Go");
if self.download_agent_registry.is_empty() {
info!(
debug!(
"Download agent registry: {:?}",
self.download_agent_registry.len()
);
@ -209,19 +209,19 @@ impl DownloadManagerBuilder {
}
if self.current_download_agent.is_some() {
info!(
debug!(
"Current download agent: {:?}",
self.current_download_agent.as_ref().unwrap().metadata()
);
return;
}
info!("Current download queue: {:?}", self.download_queue.read());
debug!("current download queue: {:?}", self.download_queue.read());
// Should always be Some if the above two statements keep going
let agent_data = self.download_queue.read().front().unwrap().clone();
info!("Starting download for {:?}", agent_data);
info!("starting download for {:?}", agent_data);
let download_agent = self
.download_agent_registry
@ -265,7 +265,7 @@ impl DownloadManagerBuilder {
active_control_flag.set(DownloadThreadControlFlag::Go);
}
fn manage_stop_signal(&mut self) {
info!("Got signal Stop");
debug!("Got signal Stop");
if let Some(active_control_flag) = self.active_control_flag.clone() {
self.set_status(DownloadManagerStatus::Paused);
@ -273,10 +273,9 @@ impl DownloadManagerBuilder {
}
}
fn manage_completed_signal(&mut self, meta: DownloadableMetadata) {
info!("Got signal Completed");
debug!("got signal Completed");
if let Some(interface) = &self.current_download_agent {
if interface.metadata() == meta {
info!("Popping consumed data");
self.remove_and_cleanup_front_download(&meta);
}
}
@ -284,7 +283,7 @@ impl DownloadManagerBuilder {
self.sender.send(DownloadManagerSignal::Go).unwrap();
}
fn manage_error_signal(&mut self, error: ApplicationDownloadError) {
info!("Got signal Error");
debug!("got signal Error");
let current_agent = self.current_download_agent.clone().unwrap();
current_agent.on_error(&self.app_handle, error.clone());
@ -295,7 +294,7 @@ impl DownloadManagerBuilder {
self.set_status(DownloadManagerStatus::Error(error));
}
fn manage_cancel_signal(&mut self, meta: &DownloadableMetadata) {
info!("Got signal Cancel");
debug!("got signal Cancel");
if let Some(current_download) = &self.current_download_agent {
if &current_download.metadata() == meta {
@ -306,32 +305,30 @@ impl DownloadManagerBuilder {
self.download_queue.pop_front();
self.cleanup_current_download();
info!("Current donwload queue: {:?}", self.download_queue.read());
debug!("Current download queue: {:?}", self.download_queue.read());
}
// TODO: Collapse these two into a single if statement somehow
else if let Some(download_agent) = self.download_agent_registry.get(meta) {
info!("Object exists in registry");
let index = self.download_queue.get_by_meta(meta);
if let Some(index) = index {
download_agent.on_cancelled(&self.app_handle);
let _ = self.download_queue.edit().remove(index).unwrap();
let removed = self.download_agent_registry.remove(meta);
info!(
"Removed {:?} from queue {:?}",
debug!(
"removed {:?} from queue {:?}",
removed.map(|x| x.metadata()),
self.download_queue.read()
);
}
}
} else if let Some(download_agent) = self.download_agent_registry.get(meta) {
info!("Object exists in registry");
let index = self.download_queue.get_by_meta(meta);
if let Some(index) = index {
download_agent.on_cancelled(&self.app_handle);
let _ = self.download_queue.edit().remove(index).unwrap();
let removed = self.download_agent_registry.remove(meta);
info!(
"Removed {:?} from queue {:?}",
debug!(
"removed {:?} from queue {:?}",
removed.map(|x| x.metadata()),
self.download_queue.read()
);

View File

@ -83,10 +83,8 @@ impl GameDownloadAgent {
// Blocking
pub fn setup_download(&self) -> Result<(), ApplicationDownloadError> {
self.ensure_manifest_exists()?;
info!("Ensured manifest exists");
self.ensure_contexts()?;
info!("Ensured contexts exists");
self.control_flag.set(DownloadThreadControlFlag::Go);
@ -95,11 +93,8 @@ impl GameDownloadAgent {
// Blocking
pub fn download(&self, app_handle: &AppHandle) -> Result<bool, ApplicationDownloadError> {
info!("Setting up download");
self.setup_download()?;
info!("Setting progress object params");
self.set_progress_object_params();
info!("Running");
let timer = Instant::now();
push_game_update(
app_handle,
@ -115,7 +110,7 @@ impl GameDownloadAgent {
.run()
.map_err(|_| ApplicationDownloadError::DownloadError);
info!(
debug!(
"{} took {}ms to download",
self.id,
timer.elapsed().as_millis()
@ -253,7 +248,7 @@ impl GameDownloadAgent {
pub fn run(&self) -> Result<bool, ()> {
let max_download_threads = DB.borrow_data().unwrap().settings.max_download_threads;
info!(
debug!(
"downloading game: {} with {} threads",
self.id, max_download_threads
);
@ -323,21 +318,16 @@ impl GameDownloadAgent {
completed_contexts_lock.len()
};
info!("Got newly completed");
// If we're not out of contexts, we're not done, so we don't fire completed
if completed_lock_len != contexts.len() {
info!("da for {} exited without completing", self.id.clone());
info!("download agent for {} exited without completing", self.id.clone());
self.stored_manifest
.set_completed_contexts(self.completed_contexts.lock().unwrap().as_slice());
info!("Setting completed contexts");
self.stored_manifest.write();
info!("Wrote completed contexts");
return Ok(false);
}
info!("Sending completed signal");
// We've completed
self.sender
.send(DownloadManagerSignal::Completed(self.metadata()))

View File

@ -221,7 +221,7 @@ pub fn uninstall_game_logic(meta: DownloadableMetadata, app_handle: &AppHandle)
let previous_state = db_handle.applications.game_statuses.get(&meta.id).cloned();
if previous_state.is_none() {
info!("uninstall job doesn't have previous state, failing silently");
warn!("uninstall job doesn't have previous state, failing silently");
return;
}
let previous_state = previous_state.unwrap();
@ -259,7 +259,7 @@ pub fn uninstall_game_logic(meta: DownloadableMetadata, app_handle: &AppHandle)
drop(db_handle);
DB.save().unwrap();
info!("uninstalled game id {}", &meta.id);
debug!("uninstalled game id {}", &meta.id);
push_game_update(
&app_handle,

View File

@ -180,7 +180,7 @@ fn setup(handle: AppHandle) -> AppState<'static> {
drop(db_handle);
info!("finished setup!");
debug!("finished setup!");
// Sync autostart state
if let Err(e) = autostart::sync_autostart_on_startup(&handle) {
@ -259,14 +259,14 @@ pub fn run() {
.setup(|app| {
let handle = app.handle().clone();
let state = setup(handle);
info!("initialized drop client");
debug!("initialized drop client");
app.manage(Mutex::new(state));
#[cfg(any(target_os = "linux", all(debug_assertions, windows)))]
{
use tauri_plugin_deep_link::DeepLinkExt;
app.deep_link().register_all()?;
info!("registered all pre-defined deep links");
debug!("registered all pre-defined deep links");
}
let handle = app.handle().clone();
@ -286,7 +286,7 @@ pub fn run() {
.unwrap();
app.deep_link().on_open_url(move |event| {
info!("handling drop:// url");
debug!("handling drop:// url");
let binding = event.urls();
let url = binding.first().unwrap();
if url.host_str().unwrap() == "handshake" {

View File

@ -316,9 +316,6 @@ impl ProcessManager<'_> {
});
self.processes.insert(meta.id, wait_thread_handle);
info!("finished spawning process");
Ok(())
}
}

View File

@ -21,7 +21,7 @@ pub fn use_remote_logic(
url: String,
state: tauri::State<'_, Mutex<AppState<'_>>>,
) -> Result<(), RemoteAccessError> {
info!("connecting to url {}", url);
debug!("connecting to url {}", url);
let base_url = Url::parse(&url)?;
// Test Drop url