Logging for JavaScript

Why ?

When you're writing some JavaScript you can miss something : a logging tool. A way to do logging with Javascript (you used it...) is to use alert(msg) Window object's method ; alert logging can quickly be very annoying when debugging some code in a for statement...

There were already some library like log4js or fvlogger (thanks for colors and icons) when I wrote this script but they were not exactly how I wanted the tool to be ; quickly :

Alexandre SIMON.

How ?

The script appends paragraph elements to a HTMLElement container identified by id attribute value LogWindow (you can also customize it setting Log.ContainerId variable value). If the container does not exists, it is created.

Usage is simple :

Log.setThreshold("debug"); // somewhere in an 'init()' function
Log.debug("Some message required to debug");
if (Log.isDebugEnabled()) {
  Log.debug("Some debug message that could have more impact on code execution "+object.heavyToStringMethod());

Tested with :


Click on the 'launch ...' links above.

Download the source code