FLOG, to replace debug() #5879
Maybe it'd be desirable to, instead of having a 'debug' and 'ohno' category, give it a concept of severity? Like err, warn, notice. e.g.
I think we want to have some pretty output showing the category next to the message, and the severity could be indicated like debug() does,
Thanks for your thoughtful ideas!
The macro can avoid evaluating arguments, which might be expensive. With a function the arguments are always evaluated. That's why debug() is a macro.
We should get away from severity levels - most logs aren't warnings or errors, they're just something normal that happened. And if they are warnings or errors we should print them.
The idea of
The big idea here is that we can log way more than we do today, because you have to opt into seeing the logs per-category.
Printing the category sounds good to me, still not sold on the severity level though. There's not really a severity associated with creating a job, etc.
One problem we've had for a while was that input had debug messages like "trying to match mapping" that were spamming on every single keypress, even if you weren't debugging input.
This would solve it by adding that to an "input" category. But what if you want to debug input, but not that particular part of input? You'd have to set it to a new category, and then you'd have to enable that category in addition to the others if you do want it.
That might turn out to be quite tricky. But on the other hand, we've never really nailed the severity levels.
What might help is:
If I'm reading this correctly, those are already in.
But that still means we need to come up with a sensible system of categories - you don't want to enable too much, and you want to be able to guess the category. I would default to the filename (minus the suffix), so you'd use "input", "input_common" and "builtin_cd", unless you wanted a more specific category (like termowner or "input-mapping").
Of course you could also make this much more elaborate (what about actual subcategories and multiple categories and....), but it's always easy to overengineer things.
I love the idea of associating color with categories. Obviously we'd have to disable it if the term doesn't support it.
Then why not call it "error"?
Having been a victim of various packages employing both a severity and category system, I strongly discourage this - it rapidly gets out of hand.
This adds a new mechanism for logging, intended to replace debug(). The entry points are FLOG and FLOGF. FLOG can be used to log a sequence of arguments, FLOGF is for printf-style formatted strings. Each call to FLOG and FLOGF requires a category. If logging for a category is not enabled, there is no effect (and arguments are not evaluated). Categories may be enabled on the command line via the -d option.