From fc7882fc961a61ca94d4f64458afd61197de14da Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 14 Nov 2026 13:23:26 -0800 Subject: [PATCH] craft-testkit: describe where formatting a log message stops at the byte limit Formatting stops at the first write that would take the message past MAX_BYTES, so a message never passes the limit. --- crates/testkit/README.md | 2 +- crates/testkit/src/log.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/testkit/README.md b/crates/testkit/README.md index 04f98831e8..1d238ccb40 100644 --- a/crates/testkit/README.md +++ b/crates/testkit/README.md @@ -32,7 +32,7 @@ The `log` feature adds `craft_testkit::log` and the `log` dependency. The module A capture raises `log::max_level()` to the level it asks for and never lowers it. When the closure panics, the capture on that thread ends and the panic continues. Records from other threads do not appear in a per-thread capture. -A capture keeps at most `MAX_RECORDS` (4,096) records and `MAX_BYTES` (1 MiB) of message and target text. Formatting a message stops once it passes `MAX_BYTES`. A record over either limit is dropped and counted, and the capture returns `CaptureError::Overflow { dropped }` instead of a partial list. For `drain`, the limits apply to each interval between drains. +A capture keeps at most `MAX_RECORDS` (4,096) records and `MAX_BYTES` (1 MiB) of message and target text. Formatting a message stops at the first write that would take it past `MAX_BYTES`. A record over either limit is dropped and counted, and the capture returns `CaptureError::Overflow { dropped }` instead of a partial list. For `drain`, the limits apply to each interval between drains. Run process-wide captures in a binary of their own, for example a `[[test]]` with `harness = false`: diff --git a/crates/testkit/src/log.rs b/crates/testkit/src/log.rs index 2b672c1aeb..d48410391f 100644 --- a/crates/testkit/src/log.rs +++ b/crates/testkit/src/log.rs @@ -18,9 +18,9 @@ //! capture filters by its own level. //! //! A capture keeps at most [`MAX_RECORDS`] records and [`MAX_BYTES`] bytes of message and target -//! text. Formatting a message stops once it passes [`MAX_BYTES`]. A record over either limit is -//! dropped and counted, and the capture then returns [`CaptureError::Overflow`] with the number -//! dropped instead of a partial list. +//! text. Formatting a message stops at the first write that would take it past [`MAX_BYTES`]. A +//! record over either limit is dropped and counted, and the capture then returns +//! [`CaptureError::Overflow`] with the number dropped instead of a partial list. use std::cell::RefCell; use std::fmt;