SpyBug - a simple framework for logging and debugging using the browser's native console. Get it from github!
SpyBug is a simple framework for logging and debugging using the browser's native console.
alert methods or use the console to dump your debug output. SpyBug helps you in the latter case. Instead of you using the raw
console.log method, you can add a layer of SpyBug. SpyBug adds an abstraction layer for you and makes it convenient to log messages to the console.
Well, you need web browser that has a console! If you're working with the latest version of Mozilla Firefox, then the add-on, Firebug, is required. You can get Firebug at http://getfirebug.com. If you're using Internet Explorer 8+ however, you just need to open up the Developer Tools window and go to the Script tab and click on the Console tab. For other browsers, please refer that browser's documentation/user-manual/help-page to find out about the console. I think Google Chrome has an in-built console. Just Google for it! I don't use Chrome, so I don't know much about it. For all you Apple fans, I think Safari too has an in-built console.
Using SpyBug is very easy! Here's how:
1. Download SpyBug.min.1.0.0.js.
2. In your HTML file, include this line in the
3. Create the SpyBug object. You'll be using this object to log your messages to the console:
var spybug = new SpyBug();
That's it! Now, to log messages to your browser console, just say:
spybug.spy("My first SpyBug log message!", spybug.INFO);
Your console should now show the current date and time along with the above message!
Thank you! Oh that: it's a type of log message you wish to log to the console. These are the types that SpyBug supports:
console.info) A message containing status information, which is usually displayed with a round, blue exclamation icon.
console.debug) A debug message which is used for temporarily displaying log messages.
Note: This may not be compatible with Internet Explorer.
console.warn) A warning message, which is usually displayed with a triangular, yellow exclamation icon.
console.error) An error message which is usually displayed with a round, red X icon.
console.log) A simple log message. This is the default log message.
That's possible too! Just say:
That'll make SpyBug ignore all the subsequent messages that you try to log using SpyBug.
Oh right, sorry, I forgot! Once again, just say:
That'll make SpyBug stop ignoring your messages and start logging again!
Yeah, you can find that out by simply saying:
It'll return either
false; depending on whether logging is enabled or disabled.
Yeah, there is a demo page showcasing the capabilities of SpyBug. It's called
SpyBug Demo.html and you can find it in the SpyBug repository on github.