chore(log): Add context to logger failure messages (#1764)

Have added a little bit more context to the error messages that occur
when if starship is unable to setup the logger. This should hopefully
make it a bit easier to work out why starship can't setup the logger.
This commit is contained in:
Thomas O'Donnell 2020-10-14 18:13:44 +02:00 committed by GitHub
parent 205fd1abdd
commit b2a5c4a3e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -25,7 +25,8 @@ impl StarshipLogger {
.join(".cache/starship")
});
fs::create_dir_all(&log_dir).expect("Unable to create log dir!");
fs::create_dir_all(&log_dir)
.unwrap_or_else(|err| panic!("Unable to create log dir {:?}: {:?}!", log_dir, err));
let session_log_file = log_dir.join(format!(
"session_{}.log",
env::var("STARSHIP_SESSION_KEY").unwrap_or_default()
@ -43,8 +44,13 @@ impl StarshipLogger {
OpenOptions::new()
.create(true)
.append(true)
.open(session_log_file)
.unwrap(),
.open(session_log_file.clone())
.unwrap_or_else(|err| {
panic!(
"Unable to open session log file {:?}: {:?}!",
session_log_file, err
)
}),
)),
log_level: env::var("STARSHIP_LOG")
.map(|level| match level.to_lowercase().as_str() {