toolkit for mdBook [mirror of my GitHub repo] docs.tonywu.dev/mdbookkit/
permalinks rust-analyzer mdbook
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: use compact format for tracing

Tony Wu 26666424 e7460868

+51 -39
+5 -3
crates/mdbook-rustdoc-links/src/client.rs
··· 233 233 234 234 let (sender, receiver) = mpsc::channel(16); 235 235 236 - let ticker = ticker!(Level::INFO, "rust-analyzer"); 237 - 238 236 let stabilizer = EventSampling { 239 237 buffer: Duration::from_millis(500), 240 238 timeout: env.config.rust_analyzer_timeout(), ··· 245 243 let (background, mut server) = MainLoop::new_client(move |_| { 246 244 let state = State { 247 245 sender, 248 - ticker: Some(ticker), 246 + ticker: Some(ticker!( 247 + Level::INFO, 248 + "rust-analyzer", 249 + "rust-analyzer indexing" 250 + )), 249 251 percent_indexed: Some(0), 250 252 last_update: None, 251 253 };
+7 -2
crates/mdbook-rustdoc-links/src/resolver.rs
··· 76 76 .await? 77 77 .pipe(Arc::new); 78 78 79 - let ticker = ticker!(Level::INFO, "resolve-items", count = request.len()); 79 + let ticker = ticker!( 80 + Level::INFO, 81 + "resolve-items", 82 + count = request.len(), 83 + "resolving items" 84 + ); 80 85 81 86 let tasks: JoinSet<Option<(String, ItemLinks)>> = request 82 87 .into_iter() 83 88 .map(|(key, pos)| { 84 89 let key = key.to_string(); 85 90 let doc = document.clone(); 86 - let ticker = ticker_item!(&ticker, Level::INFO, "resolve", item = ?key); 91 + let ticker = ticker_item!(&ticker, Level::INFO, "resolve", "{key:?}"); 87 92 async move { 88 93 for p in pos { 89 94 let resolved = doc
+37 -32
crates/mdbookkit/src/logging.rs
··· 11 11 //! # use tracing::Level; 12 12 //! # use mdbookkit::ticker; 13 13 //! # 14 - //! let ticker = ticker!(Level::INFO, "task-name", count = 63); 15 - //! // ⠋ [parent-span] task-name (0/63) ... 14 + //! let ticker = ticker!(Level::INFO, "task-name", count = 63, "running errands"); 15 + //! // ⠋ [parent-span] running errands (0/63) ... 16 16 //! ``` 17 17 //! 18 18 //! Use [`ticker_event!`][crate::ticker_event] to flash a message in the specified ticker. ··· 21 21 //! ``` 22 22 //! # use tracing::Level; 23 23 //! # use mdbookkit::{ticker, ticker_event}; 24 - //! # let ticker = ticker!(Level::INFO, "task-name", count = 63); 24 + //! # let ticker = ticker!(Level::INFO, "task-name", count = 63, "running errands"); 25 25 //! # 26 26 //! ticker_event!(&ticker, Level::INFO, "task updated"); 27 - //! // ⠋ [parent-span] task-name (0/63) ... task updated 27 + //! // ⠋ [parent-span] running errands (0/63) ... task updated 28 28 //! ``` 29 29 //! 30 30 //! Use [`ticker_item!`][crate::ticker_item] to add a subtask to the specified ticker, 31 - //! backed by a [`tracing::Span`]. The `item` field provides the displayed name. 32 - //! When the span closes, the item count in the ticker is increased by 1. 31 + //! backed by a [`tracing::Span`]. When the span closes, the item count in the ticker 32 + //! is increased by 1. 33 33 //! 34 34 //! ``` 35 35 //! # use tracing::Level; 36 36 //! # use mdbookkit::{ticker, ticker_item}; 37 - //! # let ticker = ticker!(Level::INFO, "task-name", count = 63); 37 + //! # let ticker = ticker!(Level::INFO, "task-name", count = 63, "running errands"); 38 38 //! # 39 - //! let item = ticker_item!(&ticker, Level::INFO, "task", item = "item name"); 40 - //! // ⠋ [parent-span] task-name (0/63) ... item name 39 + //! let item = ticker_item!(&ticker, Level::INFO, "task", "groceries"); 40 + //! // ⠋ [parent-span] running errands (0/63) ... groceries 41 41 //! drop(item); 42 - //! // ⠋ [parent-span] task-name (1/63) ... item name 42 + //! // ⠋ [parent-span] running errands (1/63) ... groceries 43 43 //! ``` 44 44 //! 45 45 //! If the application is configured to be in logging mode, these are emitted as regular logs. 46 46 //! 47 47 //! ```plaintext 48 - //! INFO parent-span:task-name: started 49 - //! INFO parent-span:task-name: task updated 50 - //! INFO parent-span:task-name:task{item="item name"}: started 51 - //! INFO parent-span:task-name:task{item="item name"}: finished 52 - //! INFO parent-span:task-name: finished 48 + //! INFO parent-span:task-name: started running errands count=63 49 + //! INFO parent-span:task-name: task updated running errands count=63 50 + //! INFO parent-span:task-name:task: started running errands count=63 groceries 51 + //! INFO parent-span:task-name:task: finished running errands count=63 groceries 52 + //! INFO parent-span:task-name: finished running errands count=63 53 53 //! ``` 54 54 //! 55 55 //! ### Notes ··· 147 147 .parse_lossy(MDBOOK_LOG.as_deref().unwrap_or_default()); 148 148 149 149 let logger = tracing_subscriber::fmt::layer() 150 + .compact() 150 151 .without_time() 151 - .with_target(filter.max_level_hint().unwrap_or(options.level) < LevelFilter::INFO) 152 + .with_target(filter.max_level_hint().unwrap_or(options.level) > LevelFilter::INFO) 152 153 .with_ansi(is_colored()) 153 154 .with_writer(|| TICKER.writer()) 154 155 .with_filter(if TICKER.is_enabled() { ··· 181 182 )*]; 182 183 Event::child_of($id, metadata, &fields.value_set(&values)); 183 184 }}; 185 + ( $id:expr, $metadata:expr, $format:literal $($vars:tt)* ) => {{ 186 + derive_event!($id, $metadata, "message" = format!($format $($vars)*)) 187 + }}; 184 188 } 185 189 186 190 #[macro_export] ··· 239 243 let Some(span) = ctx.span(id) else { return }; 240 244 241 245 if is_branded!(span, "ticker") { 242 - let TickerVisitor { count, .. } = TickerVisitor::from_attrs(attrs); 246 + let TickerVisitor { count, message, .. } = TickerVisitor::from_attrs(attrs); 243 247 244 248 let ticker = TickerData { 245 249 prefix: SpanPath::to_string(&span), 246 250 key: span.name(), 251 + title: message, 247 252 count, 248 253 }; 249 254 ··· 252 257 if let Some(tx) = TICKER.sender() { 253 258 tx.send(ProgressTick::TickerCreate(ticker)).ok(); 254 259 } else { 255 - derive_event!(id, span.metadata(), "message" = "started"); 260 + derive_event!(id, span.metadata(), "started"); 256 261 } 257 262 } else if is_branded!(span, "ticker.item") 258 263 && let TickerVisitor { 259 - item: Some(item), .. 264 + message: Some(item), 265 + .. 260 266 } = TickerVisitor::from_attrs(attrs) 261 267 && let Some(parent) = span.parent() 262 268 && let Some(TickerData { key, .. }) = parent.extensions().get::<TickerData>() ··· 266 272 if let Some(tx) = TICKER.sender() { 267 273 tx.send(ProgressTick::ItemOpen { key, item }).ok(); 268 274 } else { 269 - derive_event!(id, span.metadata(), "message" = "started"); 275 + derive_event!(id, span.metadata(), "started"); 270 276 } 271 277 } 272 278 } ··· 281 287 if let Some(tx) = TICKER.sender() { 282 288 tx.send(ProgressTick::TickerFinish { key }).ok(); 283 289 } else { 284 - derive_event!(id, span.metadata(), "message" = "finished"); 290 + derive_event!(id, span.metadata(), "finished"); 285 291 } 286 292 } else if let Some(parent) = span.parent() 287 293 && let Some(TickerData { key, .. }) = parent.extensions().get::<TickerData>() ··· 291 297 let item = item.clone(); 292 298 tx.send(ProgressTick::ItemDone { key, item }).ok(); 293 299 } else { 294 - derive_event!(id, span.metadata(), "message" = "finished"); 300 + derive_event!(id, span.metadata(), "finished"); 295 301 } 296 302 } 297 303 } 298 304 299 305 fn on_event(&self, event: &Event<'_>, ctx: Context<'_, S>) { 300 - if !is_branded!(event.metadata(), "timer.event") { 306 + if !is_branded!(event.metadata(), "ticker.event") { 301 307 return; 302 308 } 303 309 ··· 318 324 319 325 #[derive(Debug, Default)] 320 326 struct TickerVisitor { 321 - message: Option<String>, 322 - item: Option<Arc<str>>, 327 + message: Option<Arc<str>>, 323 328 count: Option<u64>, 324 329 } 325 330 326 331 impl Visit for TickerVisitor { 327 332 fn record_str(&mut self, field: &Field, value: &str) { 328 - match field.name() { 329 - "message" => self.message = Some(value.into()), 330 - "item" => self.item = Some(value.into()), 331 - _ => {} 333 + if field.name() == "message" { 334 + self.message = Some(value.into()) 332 335 } 333 336 } 334 337 ··· 387 390 struct TickerData { 388 391 prefix: Option<Arc<str>>, 389 392 key: &'static str, 393 + title: Option<Arc<str>>, 390 394 count: Option<u64>, 391 395 } 392 396 393 397 impl Display for TickerData { 394 398 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 399 + let title = self.title.as_deref().unwrap_or(self.key); 395 400 if let Some(ref prefix) = self.prefix { 396 - write!(f, "[{prefix}] {}", self.key) 401 + write!(f, "[{prefix}] {title}") 397 402 } else { 398 - write!(f, "{}", self.key) 403 + write!(f, "{title}") 399 404 } 400 405 } 401 406 } ··· 406 411 #[derive(Debug)] 407 412 enum ProgressTick { 408 413 TickerCreate(TickerData), 409 - TickerUpdate { key: &'static str, msg: String }, 414 + TickerUpdate { key: &'static str, msg: Arc<str> }, 410 415 ItemOpen { key: &'static str, item: Arc<str> }, 411 416 ItemDone { key: &'static str, item: Arc<str> }, 412 417 TickerFinish { key: &'static str },
+2 -2
crates/mdbookkit/src/logging/writer.rs
··· 73 73 } 74 74 75 75 let style = ProgressStyle::with_template("{spinner:.cyan} {prefix} ... {msg}") 76 - .unwrap() 76 + .expect("should be a valid template") 77 77 .tick_chars("⠇⠋⠙⠸⠴⠦⠿"); 78 78 79 79 let mut current = HashMap::new(); ··· 110 110 continue; 111 111 }; 112 112 113 - bar.set_message(msg); 113 + bar.set_message(String::from(&*msg)); 114 114 } 115 115 116 116 Ok(ProgressTick::ItemOpen { key, item }) => {