Skip to content

Instantly share code, notes, and snippets.

@abhiomkar
Created July 21, 2010 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abhiomkar/484491 to your computer and use it in GitHub Desktop.
Save abhiomkar/484491 to your computer and use it in GitHub Desktop.
User-defined console.log() function for debug messages in JavaScript. Useful if Firebug is not installed in your browser.
// Author: Abhinay Omkar
if(!window.console){
var console = {
log: function(msg){
throw new Error(msg);
}
}
}
// Use It
// If Firebug is installed in your browser the logger of Firebug will be called
// Otherwise, the above user defined function will be called.
console.log("Hello World!");
@rakeshpai
Copy link

!console will break. You don't need to use new. console.log takes any number of params.

if(!window.console) {
    var console = {
        log: function() {
            // whatever you want with arguments
        }
        ...
    }
 }

@abhiomkar
Copy link
Author

Sweet! I've modified the code as you suggested. Thanks much!

@ramses0
Copy link

ramses0 commented Jul 21, 2010

Dude. Firebug lite.

http://getfirebug.com/firebuglite

Right-Click => Add to Bookmarks or <script src=.../firebuglite.js> if you're going to be modifying the page in question anyway.

@whatgoodisaroad
Copy link

I've just written my own log wrapper function that enclosed it in a try/catch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment