One BigInt in your log data deletes every other field
One BigInt makes JSON.stringify throw, so your logger drops every other field too. What I measured, and a safe() helper that keeps Dates and Errors intact.
9 posts
One BigInt makes JSON.stringify throw, so your logger drops every other field too. What I measured, and a safe() helper that keeps Dates and Errors intact.
Batched logs sit in memory until a timer fires. Serverless freezes your function the moment it responds. Here is what I measured, and the one-line fix.
Everyone says console.time() breaks under concurrency because the second call overwrites the first. I tested it in Node, Bun and Deno, and that is not what happens. The second timer is thrown away, the fast request reports the slow request's duration, and the slow request reports nothing at all.
Structured logging only pays off if the data field has a stable shape you can query on. Nothing enforces that by default. Here's how to catch drift with schema validation that never drops the log line, using the Standard Schema spec so it works with Zod, Valibot, or nothing at all.
I set LOG_LEVEL to turn on debug logs for one feature. Nothing appeared. The rules were spelled correctly — they were just in the wrong order. Here is what I measured, and the rule that tells you which order is right.
window.onerror is the answer everyone gives. It never fires for a broken image, and the next library that loads can delete yours. Here is what to use instead, on the client and on the server, tested in a real browser.
A crash at chunks/page.js:1:518 tells you nothing. Source maps turn it back into checkout.ts:3:49. Here's how the lookup works, and the one case where it hands you a real-looking line number that is completely wrong.
Error objects have non-enumerable fields, so a logger that just JSON.stringify's them prints an empty object. Here's why, and a serializer that captures message, stack, cause chains, and AggregateErrors properly.
The problem with console.log in the browser, why a naive 'POST logs to the server' endpoint is a security hole, and how @developerehsan/nextjs-logger solves both with one import.