add tracing

This commit is contained in:
annieversary 2022-07-06 19:03:42 +01:00
parent d21212902e
commit 4136af68d8
2 changed files with 21 additions and 5 deletions

View File

@ -10,6 +10,7 @@ inventory = ["dep:inventory"]
[dependencies] [dependencies]
inventory = { version = "0.3", optional = true } inventory = { version = "0.3", optional = true }
tracing = "0.1.35"
[[example]] [[example]]
name = "inventory" name = "inventory"

View File

@ -65,12 +65,16 @@ impl Zephyr {
} }
pub fn generate_classes<'a>(&self, classes: impl IntoIterator<Item = &'a str>) -> String { pub fn generate_classes<'a>(&self, classes: impl IntoIterator<Item = &'a str>) -> String {
// TODO when we have media queries, we can do something to group them by the query, and then emit those together // TODO when we have media queries, we can do something to group them by the query,
// and then emit those together
// TODO we could return (css, seen_classes) // TODO we could return (css, seen_classes)
let mut seen_classes = vec![]; let mut seen_classes = vec![];
classes let span = tracing::trace_span!("generating classes");
let _enter = span.enter();
let classes = classes
.into_iter() .into_iter()
// get a list with one class per element // get a list with one class per element
.flat_map(|s| s.split_ascii_whitespace()) .flat_map(|s| s.split_ascii_whitespace())
@ -88,9 +92,20 @@ impl Zephyr {
} }
}) })
// we ignore errors // we ignore errors
.flat_map(|c| self.generate_class(c).ok()) .flat_map(|c| match self.generate_class(c) {
.collect::<Vec<_>>() Ok(v) => Some(v),
.join("") Err(err) => {
// trace error
tracing::error!("error generating {c}: {err:?}");
None
}
})
.collect::<Vec<_>>();
let len = classes.len();
tracing::trace!("finished generating {len} classes");
classes.join("")
} }
/// this one returns an error if parsing or generating fails /// this one returns an error if parsing or generating fails