“Abort, retry, fail” Are we really any better off now?

Node.js needs a good logging interface

Joe Honton
Apr 17 · 2 min read

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:

  1. 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.
  2. The output should conditionally include module and function names. If I’m the developer turn them on. If I’m the user omit them.
  3. 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.
  4. I prefer log “types” like progress, validation, security, debug and hopeless, instead of the traditional log “levels” like info, warn, error and 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).

Joe Honton

Written by

Using distraction-free tools for better reading, writing and publishing, and loving it!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade