Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Ensure logfile respects the validators-dir CLI flag #3003

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lighthouse/environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,21 @@ impl<E: EthSpec> EnvironmentBuilder<E> {

// 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);
}
}
}
}

Expand Down
26 changes: 17 additions & 9 deletions lighthouse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,21 +372,29 @@ fn run<E: EthSpec>(
// Construct the path to the log file.
let mut log_path: Option<PathBuf> = 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")?
};

Some(
base_path
.join(DEFAULT_VALIDATOR_DIR)
macladson marked this conversation as resolved.
Show resolved Hide resolved
.join("logs")
.join("validator")
.with_extension("log"),
)
}
_ => None,
};
}
Expand Down