{"slug": "dont-use-console-log-for-logging-what-vercels-founder-warned-about", "title": "Don’t Use console.log for Logging: What Vercel’s Founder Warned About", "summary": "Vercel founder Guillermo Rauch highlighted performance issues with console.log in production, citing a case where an old request logger reduced throughput by 21% when writing to /dev/null and 34% when logging to a terminal. Open-source developer Pooya Parsa demonstrated that timestamp caching and batched writes can cut logging overhead by 60-85%, though buffered writes risk losing logs during crashes.", "body_md": "I used AI for formatting and grammar.\n\nRecently came across this x thread by Pooya Parsa(@_pi0_). He is an open source developer of multiple libraries eg. nitrojsdev, unjs. He trying to solve the bottleneck problems that javascript web dev ecosystem faces. A lot of frameworks are dependent on this open source developers to build this high utility libraries to develop on them.\n\n// Detect dark theme var iframe = document.getElementById('tweet-2078164967367295257-77'); if (document.body.className.includes('dark-theme')) { iframe.src = \"https://platform.twitter.com/embed/Tweet.html?id=2078164967367295257&theme=dark\" }\n\nYour API is fast. The database is tuned, responses are cached, and each request finishes in milliseconds. Then you add one harmless line:\n\n```\nconsole.log(`${req.method} ${req.url}`);\n```\n\nHow bad could it be?\n\nThe old request logger in `srvx`\n\nreduced throughput by around 21% when logs were written to `/dev/null`\n\n. That result matters because `/dev/null`\n\ndiscards everything. There’s no slow disk, remote logging service, or colourful terminal output involved. The application was losing performance simply while creating timestamps, building strings, and calling the output stream.\n\nWhen logging directly to a terminal, the performance loss reached 34%.\n\nThe old logger generated a formatted timestamp for every request using locale-aware date formatting. That seems trivial until your server handles thousands of requests each second.\n\nMost of those requests share the same displayed second, yet the timestamp gets recalculated again and again.\n\nThe new logger caches the formatted time for one second. Instead of asking JavaScript’s `Intl`\n\nmachinery to rebuild the same value thousands of times, it calculates it once and reuses it.\n\nSmall change. Large recovery.\n\nThe logger also batches lines before writing them.\n\nInstead of this:\n\n```\nRequest → write\nRequest → write\nRequest → write\nRequest → write\n```\n\nIt works more like this:\n\n```\nRequest ─┐\nRequest ─┤\nRequest ─┼── buffer ── one write\nRequest ─┘\n```\n\nThe delay is only around one event-loop turn, but it greatly reduces calls to the output stream. Together, timestamp caching and batched writes cut logging overhead by roughly 60–85%, depending on where the logs were sent.\n\nGuillermo Rauch : what happens if the process crashes while logs are still waiting in memory?\n\nDuring a normal shutdown, the logger can flush its buffer. During `SIGKILL`\n\nor an OOM kill, JavaScript gets no cleanup window. The last few logs may disappear—and, annoyingly, those may be the exact logs needed to explain the crash.\n\nThat’s the trade-off: immediate writes are safer but slower; buffered writes are faster but may lose the final event-loop tick.\n\n`console.log()`\n\nis fine for local debugging and small scripts. Production logging is different. It needs structured fields, log levels, redaction, backpressure handling, buffering, and clear failure guarantees.\n\nThe real lesson isn’t that `console.log()`\n\nis universally bad. It’s that code inside a hot path must be judged by how often it runs. One cheap line repeated 20,000 times per second is no longer cheap.", "url": "https://wpnews.pro/news/dont-use-console-log-for-logging-what-vercels-founder-warned-about", "canonical_source": "https://dev.to/biomathcode/dont-use-consolelog-for-logging-what-vercels-founder-warned-about-1n46", "published_at": "2026-07-18 13:22:36+00:00", "updated_at": "2026-07-18 13:28:27.123169+00:00", "lang": "en", "topics": ["developer-tools", "ai-infrastructure"], "entities": ["Guillermo Rauch", "Vercel", "Pooya Parsa", "srvx"], "alternates": {"html": "https://wpnews.pro/news/dont-use-console-log-for-logging-what-vercels-founder-warned-about", "markdown": "https://wpnews.pro/news/dont-use-console-log-for-logging-what-vercels-founder-warned-about.md", "text": "https://wpnews.pro/news/dont-use-console-log-for-logging-what-vercels-founder-warned-about.txt", "jsonld": "https://wpnews.pro/news/dont-use-console-log-for-logging-what-vercels-founder-warned-about.jsonld"}}