use std::{error, fmt, io};
use log;
#[derive(Debug)]
pub enum InitError {
Io(io::Error),
SetLoggerError(log::SetLoggerError),
}
impl From<io::Error> for InitError {
fn from(error: io::Error) -> InitError {
InitError::Io(error)
}
}
impl From<log::SetLoggerError> for InitError {
fn from(error: log::SetLoggerError) -> InitError {
InitError::SetLoggerError(error)
}
}
impl fmt::Display for InitError {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
InitError::Io(ref e) => write!(f, "IO Error initializing logger: {}", e),
InitError::SetLoggerError(ref e) => write!(f, "logging initialization failed: {}", e),
}
}
}
impl error::Error for InitError {
fn description(&self) -> &str {
match *self {
InitError::Io(..) => "IO error while initializing logging",
InitError::SetLoggerError(..) => {
"logging system already initialized with different logger"
}
}
}
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
InitError::Io(ref e) => Some(e),
InitError::SetLoggerError(ref e) => Some(e),
}
}
}