rust.println_in_lib
Maintainability
Medium
Detects println!/eprintln! in library code instead of proper logging.
Why It Matters
Section titled “Why It Matters”Print statements in libs:
- No log levels — Can’t filter output
- No context — Missing timestamps, trace IDs
- Pollutes stdout — Interferes with user output
Example
Section titled “Example”// ❌ Before (raw print in library)pub fn process(data: &[u8]) -> Result<()> { println!("Processing {} bytes", data.len()); // ...}// ✅ After (use tracing or log)use tracing::debug;
pub fn process(data: &[u8]) -> Result<()> { debug!(bytes = data.len(), "Processing data"); // ...}What Unfault Detects
Section titled “What Unfault Detects”- println! in lib.rs or lib crates
- eprintln! for error logging
- dbg! left in production code
Auto-Fix
Section titled “Auto-Fix”Unfault can convert to tracing macros (debug!, info!, warn!, error!).