From fdc7e893d50efcbe54c78dee8d428d9c3a80c502 Mon Sep 17 00:00:00 2001 From: Innes Anderson-Morrison Date: Thu, 10 Oct 2024 07:59:39 +0100 Subject: [PATCH] #29 cleaner debug log messages for plumbing --- src/plumb.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/plumb.rs b/src/plumb.rs index f54164f..16f1295 100644 --- a/src/plumb.rs +++ b/src/plumb.rs @@ -233,6 +233,19 @@ enum Pattern { } impl Pattern { + fn kind_str(&self) -> &'static str { + match self { + Self::AddAttrs(_) => "add-attrs", + Self::DelAttr(_) => "del-attr", + Self::DataFrom(_) => "data-from", + Self::IsFile(_) => "is-file", + Self::IsDir(_) => "is-dir", + Self::Is(_, _) => "is", + Self::Matches(_, _) => "matches", + Self::Set(_, _) => "set", + } + } + fn match_and_update( &mut self, msg: &mut PlumbingMessage, @@ -247,6 +260,7 @@ impl Pattern { let re_match_and_update = |f: Field, re: &mut Regex, vars: &mut BTreeMap| { + debug!("regex match against {}", f.name()); let opt = match f { Field::Src => msg.src.as_ref(), Field::Dst => msg.dst.as_ref(), @@ -256,7 +270,7 @@ impl Pattern { let s = match opt { Some(s) => s, None => { - debug!("unable to match against {f:?} (not set in message)"); + debug!("unable to match against {} (not set in message)", f.name()); return false; } }; @@ -279,7 +293,7 @@ impl Pattern { false }; - debug!("attempting to match {self:?}"); + debug!("checking {} pattern", self.kind_str()); match self { Self::AddAttrs(attrs) => { debug!("adding attrs: {attrs:?}"); @@ -411,6 +425,17 @@ enum Field { Data, } +impl Field { + fn name(&self) -> &'static str { + match self { + Self::Src => "src", + Self::Dst => "dst", + Self::Wdir => "wdir", + Self::Data => "data", + } + } +} + impl FromStr for Field { type Err = String;