typescript.missing_structured_logging
Observability
Medium
Detects unstructured string logging instead of structured logs with fields.
Why It Matters
Section titled “Why It Matters”Unstructured logs:
- Hard to query — Can’t filter by field values
- No aggregation — Can’t count by error type
- Poor metrics — Harder to build dashboards
Example
Section titled “Example”// ❌ Before (unstructured logging)console.log(`User ${userId} logged in from ${ip}`);console.error(`Failed to process order ${orderId}: ${error}`);// ✅ After (structured logging)import pino from 'pino';const logger = pino();
logger.info({ userId, ip }, 'User logged in');logger.error({ orderId, err: error }, 'Failed to process order');What Unfault Detects
Section titled “What Unfault Detects”- Template literals in console.log
- Missing structured logger usage
- Debug prints with interpolated values
Auto-Fix
Section titled “Auto-Fix”Unfault can convert to structured logging with pino or winston.