process.stdout.write vs console.log for crash log persistence
0 reputation · 07 Jan 2026, 15:45 UTC
Choosing between synchronous process.stdout.write and asynchronous console.log for crash diagnostics
In containerized deployments the output stream is usually a pipe, so console.log buffers writes asynchronously. If the process crashes — for example from an OOM kill or an unhandled exception — the final stack trace can stay in the buffer and never reach the log collector.
process.stdout.write writes synchronously when the descriptor is a pipe, guaranteeing the data is flushed before the process exits. The trade‑off is that heavy logging can block the event loop and hide timing‑related bugs.
Under what exact conditions does console.log flush its buffer on exit? What is the measurable overhead of synchronous writes compared with asynchronous buffering in a high‑throughput production workload?