Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What information should be logged? And if the loop iterates for a million times, should we log it every time?


It could be an option when debugging like adding a trace to your function calls. And the amount of tracing (how much is stored) could be configured.

Depending on the loop syntax, presumably you'd want to know (in the case of a for loop) what variables are initialized, what the test condition is and its result, and what is altered. But, in the case of C for loops as an example, this wouldn't be easy to automate since the user can always do something like:

  for(;;) {
    if(condition) break;
    // other logic
  }
In the best case (which would be the most data-ful case and hardest to use) you'd log all changes that occur within the loop. What you really want would be smaller, like detecting the break and the condition leading to it and watch that.

More realistically, you probably want to document your loop invariants with assertions which could be optionally recorded in your trace output.


This sounds like watchpoints which can be used both for loops and (tail-)recursive functions.


I guess you're suggesting that adding a million lines to a log is excessive. But in my math, you can count lines like this: 1, 2, 3, ..., the-number-of-lines-that-fit-in-a-window, many.

Once you have more lines than fit in a window, you've already got "many" and now it's time to talk about tooling like searching logs.

A million lines of log feels like an excessive waste intuitively, but that's only because I was brought up on 8-bit computers with 16K of RAM. Now my watch has more power than probably all of the computers I owned in the 20th century put together, and a single image it displays might have more bits than a million lines of a log file.

---

I know this stuff isn't free, but we should at least consider the possibility that what we really need are proper and comprehensive logs/traces, and a "stack trace" is nothing more than an abbreviated execution trace that just happens to be relatively cheap to collect when something goes wrong.


how hard is it to log a million messages?




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: