dmesg: parse unknown facility and level as an Unknown.
This commit is contained in:
parent
5a333b463e
commit
e6364af9c6
@ -266,13 +266,10 @@ impl Dmesg<'_> {
|
|||||||
set: &Option<HashSet<T>>,
|
set: &Option<HashSet<T>>,
|
||||||
) -> impl Fn(&Result<Record, Box<dyn UError>>) -> bool + '_
|
) -> impl Fn(&Result<Record, Box<dyn UError>>) -> bool + '_
|
||||||
where
|
where
|
||||||
T: TryFrom<u32> + Eq + Hash,
|
T: From<u32> + Eq + Hash,
|
||||||
{
|
{
|
||||||
move |record: &UResult<Record>| match (record, set) {
|
move |record: &UResult<Record>| match (record, set) {
|
||||||
(Ok(record), Some(set)) => match T::try_from(record.priority_facility) {
|
(Ok(record), Some(set)) => set.contains(&T::from(record.priority_facility)),
|
||||||
Ok(t) => set.contains(&t),
|
|
||||||
Err(_) => false,
|
|
||||||
},
|
|
||||||
_ => true,
|
_ => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -344,6 +341,7 @@ enum Facility {
|
|||||||
Local5,
|
Local5,
|
||||||
Local6,
|
Local6,
|
||||||
Local7,
|
Local7,
|
||||||
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Eq, Hash, PartialEq)]
|
#[derive(Eq, Hash, PartialEq)]
|
||||||
@ -356,6 +354,7 @@ enum Level {
|
|||||||
Notice,
|
Notice,
|
||||||
Info,
|
Info,
|
||||||
Debug,
|
Debug,
|
||||||
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RecordIterator {
|
struct RecordIterator {
|
||||||
@ -436,56 +435,52 @@ impl Record {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<u32> for Level {
|
impl From<u32> for Level {
|
||||||
type Error = Box<dyn UError>;
|
fn from(value: u32) -> Self {
|
||||||
|
|
||||||
fn try_from(value: u32) -> UResult<Self> {
|
|
||||||
let priority = value & 0b111;
|
let priority = value & 0b111;
|
||||||
match priority {
|
match priority {
|
||||||
0 => Ok(Level::Emerg),
|
0 => Level::Emerg,
|
||||||
1 => Ok(Level::Alert),
|
1 => Level::Alert,
|
||||||
2 => Ok(Level::Crit),
|
2 => Level::Crit,
|
||||||
3 => Ok(Level::Err),
|
3 => Level::Err,
|
||||||
4 => Ok(Level::Warn),
|
4 => Level::Warn,
|
||||||
5 => Ok(Level::Notice),
|
5 => Level::Notice,
|
||||||
6 => Ok(Level::Info),
|
6 => Level::Info,
|
||||||
7 => Ok(Level::Debug),
|
7 => Level::Debug,
|
||||||
_ => todo!(),
|
_ => Level::Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<u32> for Facility {
|
impl From<u32> for Facility {
|
||||||
type Error = Box<dyn UError>;
|
fn from(value: u32) -> Self {
|
||||||
|
|
||||||
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
|
||||||
let facility = (value >> 3) as u8;
|
let facility = (value >> 3) as u8;
|
||||||
match facility {
|
match facility {
|
||||||
0 => Ok(Facility::Kern),
|
0 => Facility::Kern,
|
||||||
1 => Ok(Facility::User),
|
1 => Facility::User,
|
||||||
2 => Ok(Facility::Mail),
|
2 => Facility::Mail,
|
||||||
3 => Ok(Facility::Daemon),
|
3 => Facility::Daemon,
|
||||||
4 => Ok(Facility::Auth),
|
4 => Facility::Auth,
|
||||||
5 => Ok(Facility::Syslog),
|
5 => Facility::Syslog,
|
||||||
6 => Ok(Facility::Lpr),
|
6 => Facility::Lpr,
|
||||||
7 => Ok(Facility::News),
|
7 => Facility::News,
|
||||||
8 => Ok(Facility::Uucp),
|
8 => Facility::Uucp,
|
||||||
9 => Ok(Facility::Cron),
|
9 => Facility::Cron,
|
||||||
10 => Ok(Facility::Authpriv),
|
10 => Facility::Authpriv,
|
||||||
11 => Ok(Facility::Ftp),
|
11 => Facility::Ftp,
|
||||||
12 => Ok(Facility::Res0),
|
12 => Facility::Res0,
|
||||||
13 => Ok(Facility::Res1),
|
13 => Facility::Res1,
|
||||||
14 => Ok(Facility::Res2),
|
14 => Facility::Res2,
|
||||||
15 => Ok(Facility::Res3),
|
15 => Facility::Res3,
|
||||||
16 => Ok(Facility::Local0),
|
16 => Facility::Local0,
|
||||||
17 => Ok(Facility::Local1),
|
17 => Facility::Local1,
|
||||||
18 => Ok(Facility::Local2),
|
18 => Facility::Local2,
|
||||||
19 => Ok(Facility::Local3),
|
19 => Facility::Local3,
|
||||||
20 => Ok(Facility::Local4),
|
20 => Facility::Local4,
|
||||||
21 => Ok(Facility::Local5),
|
21 => Facility::Local5,
|
||||||
22 => Ok(Facility::Local6),
|
22 => Facility::Local6,
|
||||||
23 => Ok(Facility::Local7),
|
23 => Facility::Local7,
|
||||||
_ => todo!(),
|
_ => Facility::Unknown,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user