diff --git a/lighthouse/environment/src/lib.rs b/lighthouse/environment/src/lib.rs index 448c84b54d..91feef5b05 100644 --- a/lighthouse/environment/src/lib.rs +++ b/lighthouse/environment/src/lib.rs @@ -182,7 +182,21 @@ impl EnvironmentBuilder { // Create the necessary directories for the correct service and network. if !dir.exists() { - create_dir_all(dir).map_err(|e| format!("Unable to create directory: {:?}", e))?; + let res = create_dir_all(dir); + + // If the directories cannot be created, warn and disable the logger. + match res { + Ok(_) => (), + Err(e) => { + let log = stdout_logger; + warn!( + log, + "Background file logging is disabled"; + "error" => e); + self.log = Some(log); + return Ok(self); + } + } } } diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 51c1075cdb..2f04b95ca4 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -372,21 +372,28 @@ fn run( // Construct the path to the log file. let mut log_path: Option = clap_utils::parse_optional(matches, "logfile")?; if log_path.is_none() { - log_path = match matches.subcommand_name() { - Some("beacon_node") => Some( + log_path = match matches.subcommand() { + ("beacon_node", _) => Some( parse_path_or_default(matches, "datadir")? .join(DEFAULT_BEACON_NODE_DIR) .join("logs") .join("beacon") .with_extension("log"), ), - Some("validator_client") => Some( - parse_path_or_default(matches, "datadir")? - .join(DEFAULT_VALIDATOR_DIR) - .join("logs") - .join("validator") - .with_extension("log"), - ), + ("validator_client", Some(vc_matches)) => { + let base_path = if vc_matches.is_present("validators-dir") { + parse_path_or_default(vc_matches, "validators-dir")? + } else { + parse_path_or_default(matches, "datadir")?.join(DEFAULT_VALIDATOR_DIR) + }; + + Some( + base_path + .join("logs") + .join("validator") + .with_extension("log"), + ) + } _ => None, }; }