use log and env_logger, and add some logging around sync

This commit is contained in:
Dustin J. Mitchell 2020-11-29 18:18:28 -05:00
parent c117494ce6
commit 0a1ee470f7
13 changed files with 109 additions and 14 deletions

View file

@ -11,6 +11,8 @@ failure = "^0.1.8"
prettytable-rs = "^0.8.0"
config = { version="^0.10.1", default-features=false, features=["yaml"] }
dirs = "^3.0.1"
log = "^0.4.11"
env_logger = "^0.8.2"
[dev-dependencies]
assert_cmd = "^1.0.1"

View file

@ -17,6 +17,7 @@ fn bail<E: std::fmt::Display>(err: E, output: Output, code: i32) -> ! {
}
fn main() {
env_logger::init();
let command = match parse_command_line(std::env::args_os()) {
Ok(command) => command,
Err(err) => {

View file

@ -66,9 +66,9 @@ impl CommandInvocation {
pub(super) fn get_replica(&self) -> Fallible<Replica> {
let settings = self.get_settings()?;
let replica_config = ReplicaConfig {
taskdb_dir: settings.get_str("data_dir")?.into(),
};
let taskdb_dir = settings.get_str("data_dir")?.into();
log::debug!("Replica data_dir: {:?}", taskdb_dir);
let replica_config = ReplicaConfig { taskdb_dir };
Ok(Replica::from_config(replica_config)?)
}
@ -76,8 +76,11 @@ impl CommandInvocation {
let settings = self.get_settings()?;
let client_id = settings.get_str("server_client_id")?;
let client_id = Uuid::parse_str(&client_id)?;
let origin = settings.get_str("server_origin")?;
log::debug!("Using sync-server with origin {}", origin);
log::debug!("Sync client ID: {}", client_id);
Ok(server::from_config(ServerConfig::Remote {
origin: settings.get_str("server_origin")?,
origin,
client_id,
})?)
}

View file

@ -18,12 +18,14 @@ pub(crate) fn read_settings() -> Fallible<Config> {
// load either from the path in TASKCHAMPION_CONFIG, or from CONFIG_DIR/taskchampion
if let Some(config_file) = env::var_os("TASKCHAMPION_CONFIG") {
log::debug!("Loading configuration from {:?}", config_file);
let config_file: PathBuf = config_file.into();
let config_file: File<FileSourceFile> = config_file.into();
settings.merge(config_file.required(true))?;
env::remove_var("TASKCHAMPION_CONFIG");
} else if let Some(mut dir) = dirs::config_dir() {
dir.push("taskchampion");
log::debug!("Loading configuration from {:?} (optional)", dir);
let config_file: File<FileSourceFile> = dir.into();
settings.merge(config_file.required(false))?;
}