Skip to content

Commit

Permalink
Fixes ProvableHQ#2098: add creating logfile parents
Browse files Browse the repository at this point in the history
  • Loading branch information
zvolin committed Nov 28, 2022
1 parent 7cae118 commit 237e630
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli/src/helpers/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ pub fn initialize_logger<P: AsRef<Path>>(verbosity: u8, nodisplay: bool, logfile
}
});

// Create the directories tree for a logfile if it doesn't exist.
let logfile_dir = logfile.as_ref().parent().expect("Root directory passed as a logfile");
if !logfile_dir.exists() {
std::fs::create_dir_all(logfile_dir)
.expect("Failed to create a directories: '{logfile_dir}', please check if user has permissions");
}
// Create a file to write logs to.
let logfile =
File::options().append(true).create(true).open(logfile).expect("Failed to open the file for writing logs");
Expand Down

0 comments on commit 237e630

Please sign in to comment.