Logging via $.jog — easy to use, lots of power

Logging via $.jog — easy to use, lots of power

I looked over the existing logging packages and none of them were sophisticated enough for my needs, so I wrote another one, $.jog, available at http://kcrca.github.com/jog/

Jog is a JavaScript/JQuery logging package for application logging, analogous to Java packages such as log4j or java.util.logging. It allows you to separate your logs into various areas so you can turn on the logs of one area without seeing all the others, especially those of plugins or other packages you may be using. Using jog usually is as simple as this:
  1. $.jog('options').info('Reading user option settings');

This creates an informational-level log message for the "options" area of your code to indicate you were, well, reading the user option settings.

There are several existing log packages for JQuery, so why does this one need to exist? None of the others had the ability to do two important things for real-world, durable, usable logging: areas and handlers.

Logging areas let you split logging for one part of your code from other parts and control them independently. This is critical for plugins and other shared code. Without areas, if someone uses logging for their own stuff, they also see your log messages. This gets much worse if they are using multiple plugins. So you need to strip log statements as part of releasing your code, which defeats the purpose. Jog has areas, so you can leave log messages in place and they won't bother anyone else — unless you ask them to turn it on to help debug a problem they've found.

Handlers are important because plugins and programmers differ. Console log messages can be ugly and difficult to save, but are simple and don't interfere with your own page. HTML logs do interfere, but CSS can make it easier to see what's up, and you can search and save. Logs in a popup don't interfere and can handle logs from multiple windows in one place, yet having another window can be a hassle. And alerts, well, you know how unpleasant they are — and how necessary at times.

As you can see, depending on how you like to work and many other factors, being able to control how message are displayed is a powerful thing. And beyond that, you can add a handle to send messages to your server, or one that uses Growl, or ...

So that is why I found it worth the time to write this. I hope it helps you out.