I have developed a small utility library, which helps with managing logging of your JavaScript applications.
Here are some features it supports:

  • Turn logging on and off
  • Support for Firebug console and log4javascript
  • Redefine console.log, console.warn, … (all console logging methods) through methods from log4javascript, if console is not detected

All you have to do is to keep on logging with firebug just as you did before! The problem occurs when you want to debug n a browser that doesn’t have Firebug enabled! Well, that should be no problem! Just include jslog.js and log4javascript-1.4.1.js and all logging that goes through console.log will now appear to the popup window log4javascript creates!

So jslog.js is a nice utility which allows you to work with two logging strategies, but using a single API, which you already know, the Firebug console

Another facility is disabling logging – in one single line! This is especially useful when going live! You don’t want to go through all your code and modify it! Use jslog.logging.init(false)

A small tutorial.
Include <script type=”text/javascript” src=”jslog.js”></script>

    jslog.logging.init(true);
    console.log('hello','this will be logged');
    
    jslog.logging.init(false);
    console.warn('sorry...','this log will not appear');

When you want to log in non-firebug environments, just include the following in your html file:
<script type=”text/javascript” src=”log4javascript.js”></script>
<script type=”text/javascript” src=”jslog.js”></script>

//You don't have to change your code.
//if jslog.js detects no console to be available,
//it creates one and redirects logging to log4javascript
    jslog.logging.init(true);
    console.log('hello','this will be logged');
    
    jslog.logging.setEnabled(false);
    console.warn('sorry...','this log will not appear');

If log4javascript.js is not included in the page and no Firebug console is detected, jslog will detect this and will just be silent, even if logging is enabled. It will not throw an error!

Download it here!

So…. happy logging! For questions and support, contact me!

Credits to Tim Down for his awesome log4javascript library!