1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use crate::log_specification::LogSpecification;
use log;
use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub enum FlexiLoggerError {
BadDirectory,
CleanupThread(std::io::Error),
Io(std::io::Error),
#[cfg(feature = "specfile")]
Notify(notify::Error),
#[cfg(feature = "specfile")]
Toml(toml::de::Error),
LevelFilter(String),
Parse(Vec<String>, LogSpecification),
Log(log::SetLoggerError),
Poison,
}
impl fmt::Display for FlexiLoggerError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::BadDirectory => f.write_str("Bad directory"),
Self::CleanupThread(ref err) | Self::Io(ref err) => fmt::Display::fmt(err, f),
Self::LevelFilter(ref s) => f.write_str(s),
#[cfg(feature = "specfile")]
Self::Notify(ref err) => fmt::Display::fmt(err, f),
#[cfg(feature = "specfile")]
Self::Toml(ref err) => fmt::Display::fmt(err, f),
Self::Parse(ref vec, ref logspec) => {
for s in vec {
f.write_str(&format!("parse error: \'{}\', ", s))?;
}
f.write_str(&format!("resulting logspec: {:?}", logspec))?;
Ok(())
}
Self::Log(ref err) => fmt::Display::fmt(err, f),
Self::Poison => fmt::Display::fmt("Some synchronization object is poisoned", f),
}
}
}
impl Error for FlexiLoggerError {}
impl From<log::SetLoggerError> for FlexiLoggerError {
#[must_use]
fn from(err: log::SetLoggerError) -> Self {
Self::Log(err)
}
}
impl From<std::io::Error> for FlexiLoggerError {
#[must_use]
fn from(err: std::io::Error) -> Self {
Self::Io(err)
}
}
impl From<glob::PatternError> for FlexiLoggerError {
#[must_use]
fn from(err: glob::PatternError) -> Self {
Self::Io(std::io::Error::new(std::io::ErrorKind::Other, err))
}
}
#[cfg(feature = "specfile")]
impl From<toml::de::Error> for FlexiLoggerError {
#[must_use]
fn from(err: toml::de::Error) -> Self {
Self::Toml(err)
}
}
#[cfg(feature = "specfile")]
impl From<notify::Error> for FlexiLoggerError {
#[must_use]
fn from(err: notify::Error) -> Self {
Self::Notify(err)
}
}