jQuery.log(), Logging plugin for jQuery
Firebug has a great number of methods for logging such as console.log, console.debug, console.info, console.warn ... All these methods provide you with logging messages in Firebug console, but with different icons. While console.log is very convenient, not all browsers support it, and you may get an error message because console.log is not defined.
Creating jQuery plug-in for logging. jQuery.log()
jQuery is an excellent library and allows a lot of kinds of stuff, and one of the most important features is creating plug-ins. All plug-in in jQuery have pattern like the following:
This patterns allow you to user $ for accessing jQuery inside of plug-in and help to hide some internal methods and properties because of closure. I want to access my logging plug-in this way
The code for jQuery log plug-in is below
Inside of plug-in, I check if the browser supports console because if this is an old version of Internet Explorer, the console will be undefined. There are at least two types of checking if the console is defined, the first is check if it inside of a window, and the second, check if it is not undefined, I prefer the second. I put just console.log() method inside of my logging method, but if you need to support more browsers, for example, Opera... you can add more code there.