Refactor LogError
This commit is contained in:
parent
aa9258e122
commit
67e86e4d74
2 changed files with 8 additions and 10 deletions
|
@ -132,8 +132,10 @@ impl From<std::str::Utf8Error> for PaperoniError {
|
|||
pub enum LogError {
|
||||
#[error(transparent)]
|
||||
FlexiError(#[from] FlexiLoggerError),
|
||||
#[error("Wrong log directory: {0}")]
|
||||
LogDirectoryError(String),
|
||||
#[error("Unable to get user directories for logging purposes")]
|
||||
UserDirectoriesError,
|
||||
#[error("Can't create log directory: {0}")]
|
||||
CreateLogDirectoryError(#[from] std::io::Error),
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
12
src/logs.rs
12
src/logs.rs
|
@ -166,12 +166,10 @@ pub fn init_logger(
|
|||
let formatted_timestamp = start_time.format("%Y-%m-%d_%H-%M-%S");
|
||||
let mut logger = flexi_logger::Logger::with(log_spec);
|
||||
|
||||
if is_logging_to_file && (!paperoni_dir.is_dir() || !log_dir.is_dir()) {
|
||||
if let Err(e) = fs::create_dir_all(&log_dir) {
|
||||
return Err(Error::LogDirectoryError(format!("Unable to create paperoni directories on home directory for logging purposes\n{}",e)));
|
||||
}
|
||||
}
|
||||
if is_logging_to_file {
|
||||
if !paperoni_dir.is_dir() || !log_dir.is_dir() {
|
||||
fs::create_dir_all(&log_dir)?;
|
||||
}
|
||||
logger = logger
|
||||
.directory(log_dir)
|
||||
.discriminant(formatted_timestamp.to_string())
|
||||
|
@ -181,9 +179,7 @@ pub fn init_logger(
|
|||
logger.start()?;
|
||||
Ok(())
|
||||
}
|
||||
None => Err(Error::LogDirectoryError(
|
||||
"Unable to get user directories for logging purposes".to_string(),
|
||||
)),
|
||||
None => Err(Error::UserDirectoriesError),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue