Skip to content

Commit

Permalink
chore(log): Add context to logger failure messages (starship#1764)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andytom authored Oct 14, 2020
1 parent 205fd1a commit b2a5c4a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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() {
Expand Down

0 comments on commit b2a5c4a

Please sign in to comment.