use std::fmt;
#[derive(Debug, Clone, PartialEq)]
pub enum LoggerError {
FileCreationFailed {
path: String,
reason: String,
},
DirectoryCreationFailed {
path: String,
reason: String,
},
WritePermissionDenied {
path: String,
},
DiskFull {
path: String,
bytes_attempted: usize,
},
RotationFailed {
current_file: String,
backup_file: String,
reason: String,
},
}
impl fmt::Display for LoggerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
LoggerError::FileCreationFailed {path, reason} => {
write!(f, "Failed to create log file '{}' : {}", path, reason)
}
LoggerError::DirectoryCreationFailed {path,reason} => {
write!(f, "Failed to create directory '{}': {}", path, reason)
}
LoggerError::WritePermissionDenied {path} => {
write!(f, "Persmission denied writing to '{}'", path)
}
LoggerError::DiskFull {path, bytes_attempted} => {
write!(f, "Disk full: could not write {} bytes to '{}'", bytes_attempted, path)
}
LoggerError::RotationFailed {current_file, backup_file, reason} => {
write!(f, "Log rotation failed: '{}' -> '{}': {}", current_file, backup_file, reason)
}
}
}
}
impl std::error::Error for LoggerError {}
pub type LoggerResult<T> = Result<T, LoggerError>;