Saturday, February 14, 2015

Choosing a JavaScript logging frameworks

I've been recently writing some web-based javascript application, and found myself confronting with the problem of choosing a proper way of logging, in order to understand what happens to the application itself (potentially, even on someone else's PC). There are many frameworks around and many persons had the same problem, now I want to share my experience. Due to node.js being very popolar, it's quite easy to find something that works with node.js but is not so suitable to a web application, so this quest has become a bit more difficult.

After some crawling, I chose to test:
  1. log4javascript - http://log4javascript.org;
  2. stritti log4js  - http://stritti.github.io/log4js/;
  3. loglevel - http://pimterry.github.io/loglevel/.
The first one, log4javascript is really easy to setup and it is nice, as it provides you with complete capabilities and a nice custom GUI, that's really independent from the browser.
It does not preserve the original code's line numbers, this is quite uncomfortable.

The second one, stritti log4js, is also very complete, is similar to log4j and is very flexible. It is not so easy to setup, and I found it to do much more things than I really needed.

The third one has been my choice - it is trivial to setup, the library is only 3Kb in size, and does only what I finally realized I was really looking for.
It fully integrates with the browser's console window, so you have to use that one, but modern browsers have quite a good console window so this is good. It does not break on older browsers, although in these cases it does not log anything.
It completely preserves original line number - this is a really important feature.
So, I chose the third option, loglevel, and even after having worked with it I really recommend it for basic scenarios.
If you want to redirect logging elsewhere, the other two choices are really fine.

No comments: