Skip to main content

cossh/log/
errors.rs

1//! Logging-related error types.
2
3use std::{error::Error, fmt, io};
4
5/// Errors returned by debug and SSH logging sinks.
6#[derive(Debug)]
7pub enum LogError {
8    /// I/O error while writing to log files.
9    IoError(io::Error),
10    /// Failed to create log directories.
11    DirectoryCreationError(String),
12    /// Error while formatting log output.
13    FormattingError(String),
14}
15
16impl fmt::Display for LogError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            LogError::IoError(err) => write!(f, "I/O error: {}", err),
20            LogError::DirectoryCreationError(msg) => {
21                write!(f, "Failed to create directory: {}", msg)
22            }
23            LogError::FormattingError(msg) => write!(f, "Formatting error: {}", msg),
24        }
25    }
26}
27
28impl Error for LogError {}
29
30impl From<io::Error> for LogError {
31    fn from(err: io::Error) -> Self {
32        LogError::IoError(err)
33    }
34}