From 4136af68d884a09fa6db3524965af158e8c590e6 Mon Sep 17 00:00:00 2001 From: annieversary Date: Wed, 6 Jul 2022 19:03:42 +0100 Subject: [PATCH] add tracing --- Cargo.toml | 1 + src/lib.rs | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 43ef9d1..4ebc07f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ inventory = ["dep:inventory"] [dependencies] inventory = { version = "0.3", optional = true } +tracing = "0.1.35" [[example]] name = "inventory" diff --git a/src/lib.rs b/src/lib.rs index 8b114c2..91ef759 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,12 +65,16 @@ impl Zephyr { } pub fn generate_classes<'a>(&self, classes: impl IntoIterator) -> 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) let mut seen_classes = vec![]; - classes + let span = tracing::trace_span!("generating classes"); + let _enter = span.enter(); + + let classes = classes .into_iter() // get a list with one class per element .flat_map(|s| s.split_ascii_whitespace()) @@ -88,9 +92,20 @@ impl Zephyr { } }) // we ignore errors - .flat_map(|c| self.generate_class(c).ok()) - .collect::>() - .join("") + .flat_map(|c| match self.generate_class(c) { + Ok(v) => Some(v), + Err(err) => { + // trace error + tracing::error!("error generating {c}: {err:?}"); + None + } + }) + .collect::>(); + + let len = classes.len(); + tracing::trace!("finished generating {len} classes"); + + classes.join("") } /// this one returns an error if parsing or generating fails