Logging In Loop (ARCH3164)
Key typescript.logging.logging-in-loop · Severity info · Category logging
Log statements inside a loop body can flood log sinks over large collections. This raises storage cost and buries real events in noise.
Incorrect
Section titled “Incorrect”function importRows(rows: Row[]) { for (const row of rows) { logger.info("processing row", { id: row.id }); process(row); }}Correct
Section titled “Correct”function importRows(rows: Row[]) { for (const row of rows) { process(row); } logger.info("rows processed", { count: rows.length });}Aggregate results and write a single summary log outside the loop instead of logging per iteration.