From 1fa7009ce1e08a65cb7fa819ffaf8ac6631126da Mon Sep 17 00:00:00 2001 From: "Derek J. Clark" Date: Mon, 28 Nov 2022 15:04:49 -0800 Subject: [PATCH] Restore logpath for deployment. Resolve warning from copy() not having err handled. --- backend/Cargo.lock | 4 ++-- backend/Cargo.toml | 2 +- backend/src/main.rs | 14 +++++++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 366d7f7..94ef8d0 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1077,9 +1077,9 @@ dependencies = [ [[package]] name = "usdpl-back" -version = "0.7.1" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88709aa9d6c5c65c0e8715dbb716b253ceebd0bd1097c4e5316660320ae604e1" +checksum = "58928ed65332c30b9b9be5140fcdab97e45db679a5845d829aa26492765272e5" dependencies = [ "async-recursion", "async-trait", diff --git a/backend/Cargo.toml b/backend/Cargo.toml index a3a324a..5b9f403 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -usdpl-back = { version = "0.7.1", features = ["blocking"]} +usdpl-back = { version = "0.7.2", features = ["blocking"]} serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/backend/src/main.rs b/backend/src/main.rs index 998277b..486a301 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -23,12 +23,19 @@ fn main() -> Result<(), ()> { let log_filepath = usdpl_back::api::dirs::home() .unwrap_or_else(|| "/tmp/".into()) .join(PACKAGE_NAME.to_owned()+".log"); - println!("Found home dir: {:?}", log_filepath); + #[cfg(not(debug_assertions))] + let log_filepath = std::path::PathBuf.new("/tmp/"+PACKAGE_NAME.to_owned()+".log"); + #[cfg(debug_assertions)] + let old_log_filepath = usdpl_back::api::dirs::home() + .unwrap_or_else(|| "/tmp/".into()) + .join(PACKAGE_NAME.to_owned()+".log.old"); + #[cfg(debug_assertions)] { if std::path::Path::new(&log_filepath).exists() { - std::fs::copy(&log_filepath, &log_filepath.join(".old")); + std::fs::copy(&log_filepath, &old_log_filepath).expect("Unable to increment logs. Do you have write permissions?"); } } + #[cfg(debug_assertions)] WriteLogger::init( #[cfg(debug_assertions)] { @@ -42,7 +49,8 @@ fn main() -> Result<(), ()> { std::fs::File::create(&log_filepath).unwrap(), ) .unwrap(); - log::debug!("Loggin started at {:?}.", log_filepath); + log::debug!("Logging to: {:?}.", log_filepath); + println!("Logging to: {:?}", log_filepath); log::info!("Starting back-end ({} v{})", PACKAGE_NAME, PACKAGE_VERSION); println!("Starting back-end ({} v{})", PACKAGE_NAME, PACKAGE_VERSION);