Skip to content

Commit

Permalink
#29 cleaner debug log messages for plumbing
Browse files Browse the repository at this point in the history
  • Loading branch information
sminez committed Oct 10, 2024
1 parent b24cfed commit fdc7e89
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/plumb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -247,6 +260,7 @@ impl Pattern {

let re_match_and_update =
|f: Field, re: &mut Regex, vars: &mut BTreeMap<String, String>| {
debug!("regex match against {}", f.name());
let opt = match f {
Field::Src => msg.src.as_ref(),
Field::Dst => msg.dst.as_ref(),
Expand All @@ -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;
}
};
Expand All @@ -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:?}");
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit fdc7e89

Please sign in to comment.