“Abort, retry, fail” Are we really any better off now?
Node.js needs a good logging interface
Alon Nisser makes a very good point here. I’ve developed more than a dozen Node.js tools and each have needed a way to send important information back to the user or the developer.
Sometimes it’s just progress reporting, “I’m still working on it, I’ve gotten to this point.”
Other times it’s feedback about success or failure, “That worked,” or “that didn’t work, but I’m going to keep processing,” or “that was such a significant failure that there’s no use going any further.”
And of course sometimes, the message comes from out of the blue, from some unknown function, and for some unknown reason. Without a stack trace, I’m in for a long debugging session.
Before settling on an acceptable logging interface, I went through three very different attempts to get it right. Now I have something that fits my needs, but probably doesn’t fit your needs. And presumably, by necessity, you’ve got something that you’ve figured out. But what about that essential third-party lib that we both use. Hmm.
The basic requirements that I’m looking for are:
- The interface must be a one-liner. Since there are going to be many, many conditional statements triggering possible messages, I’ll want to keep my code as uncluttered as possible.
- The output should conditionally include module and function names. If I’m the developer turn them on. If I’m the user omit them.
- The output should conditionally include a stack trace. But let’s be reasonable here: nobody wants a Java style trace that’s 50 lines deep. And nobody needs a stack trace when the message itself says it all.
- I prefer log “types” like
hopeless, instead of the traditional log “levels” like
fatal. Log types are orthogonal to each other and can be individually turned on and off.
Let’s face it. Nobody want’s to be up that creek without a paddle!
By the way, log levels originated from IBM mainframe days, which as I remember were numeric (4, 8, 12, and 16) and were “spooled” to the output device (printer, tape, DASD, console, or TSO).