Clean up logging (#8)

This commit is contained in:
Adam Cooper 2022-03-21 03:43:56 -04:00
parent 3c6afa56c4
commit 5bb7fc6eaf

View file

@ -1,6 +1,6 @@
extern crate xdg; extern crate xdg;
use env_logger::{Env, Target}; use env_logger::Env;
use log::debug; use log::debug;
use reqwest; use reqwest;
use serde::Deserialize; use serde::Deserialize;
@ -109,10 +109,12 @@ pub struct Collection {
} }
fn init() -> Result<Config, Box<dyn std::error::Error>> { fn init() -> Result<Config, Box<dyn std::error::Error>> {
debug!("[init] Entering function...");
let xdg_dirs = xdg::BaseDirectories::with_prefix("publicise-rs").unwrap(); let xdg_dirs = xdg::BaseDirectories::with_prefix("publicise-rs").unwrap();
let config_path = xdg_dirs.find_config_file("config.toml").unwrap(); let config_path = xdg_dirs.find_config_file("config.toml").unwrap();
let config_file_contents = fs::read_to_string(config_path).unwrap(); let config_file_contents = fs::read_to_string(config_path).unwrap();
let config: Config = toml::from_str(&config_file_contents).unwrap(); let config: Config = toml::from_str(&config_file_contents).unwrap();
debug!("[init] config: {:?}", config);
return Ok(config); return Ok(config);
} }
@ -224,9 +226,7 @@ async fn traverse(mut result: Multistatus, config: &Config) -> Result<bool, Box<
#[tokio::main] #[tokio::main]
async fn main() -> std::io::Result<()> { async fn main() -> std::io::Result<()> {
env_logger::Builder::from_env(Env::default().default_filter_or("debug")) env_logger::Builder::from_env(Env::default()).init();
.target(Target::Stdout)
.init();
println!("Publicise it!\n\n"); println!("Publicise it!\n\n");
let mut config = init().unwrap(); let mut config = init().unwrap();
@ -234,7 +234,7 @@ async fn main() -> std::io::Result<()> {
let output = Command::new(&config.credentials.password_script.as_ref().unwrap()).output().unwrap(); let output = Command::new(&config.credentials.password_script.as_ref().unwrap()).output().unwrap();
config.credentials.password = Some(String::from_utf8(output.stdout).unwrap()); config.credentials.password = Some(String::from_utf8(output.stdout).unwrap());
} }
debug!("{:?}", &config); debug!("[main] {:?}", &config);
let full_path = &(String::from("/remote.php/dav/files/") + &config.credentials.username + "/" + &config.paths.target); let full_path = &(String::from("/remote.php/dav/files/") + &config.credentials.username + "/" + &config.paths.target);
let folder_contents: String = let folder_contents: String =
get_folder_contents(full_path, &config) get_folder_contents(full_path, &config)
@ -242,7 +242,7 @@ async fn main() -> std::io::Result<()> {
.unwrap(); .unwrap();
let result: Multistatus = from_str(&folder_contents).unwrap(); let result: Multistatus = from_str(&folder_contents).unwrap();
debug!("{:?}", result); debug!("[main] {:?}", result);
let _ = traverse(result, &config).await.unwrap(); let _ = traverse(result, &config).await.unwrap();
Ok(()) Ok(())