jQuery.log(), Logging plugin for jQuery
Firebug has a significant 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 a 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 critical features is creating your plug-ins. All plug-in in jQuery has a pattern like the following:
These 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 latter. 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.