sdConsole is a Javascript class used to present logging, warning, error, and debug messages to the user. These messages will be shown:
- in the firebug console if the firebug extension is installed,
- in a console text area on the current webpage if an HTML element with the id "sdConsoleId" is defined,
- in the browser status bar (needs to be enabled in Firefox preferences),
- in the browser title bar (see comments in source),
- or in pop-up alerts (see comments in source).
- Debug messages with a debugLevel <= SD.DEBUG_LEVEL will be shown.
- See this page for an example of sdConsole.
The sdConsole command syntax is as follows:
Command Syntax:
SD.console.log(string message);
SD.console.warn(string message);
SD.console.error(string message);
SD.console.debug(string message, integer debugLevel);
And the sdConsole Javascript source is:
/*!
* ====================================================================
* $Id: SDConsole.js 229 2010-11-06 16:22:52Z dgd $
* Copyright © 2009 - 2010 David DeGroote, Symmetric Designs. All rights reserved.
*/
/*jslint undef:false, white:false, plusplus:false, onevar:false, bitwise:false */
// Create our global namespace if it's not already defined
if (typeof SD === "undefined")
{
SD = {};
}
else if (typeof SD !== "object")
{
throw new Error("SD exists and is not an object!");
}
////////////////////////////////////////////
// Default debug level
SD.DEBUG_LEVEL = 1;
// Default notification method for errors:
//SD.NOTIFY_METHOD = 'alert'; // Can get anoying if there are a lot of messages.
//SD.NOTIFY_METHOD = 'title'; // Multiple messages get overwritten.
SD.NOTIFY_METHOD = 'status'; // Need to enable in Firefox
// (preferences / Content / Advanced Javascript / Change status bar text).
// (Multiple messages get overwritten.)
SD.console = {};
SD.console.log = function(msg)
{
// Modified from: http://alvinabad.wordpress.com/2009/03/06/firebug-console-object-cannot-be-overridden/
if (typeof(console) !== 'undefined')
{
if (typeof(console.log) === 'function')
{
console.log(msg);
}
}
var sdConsoleElement = document.getElementById('sdConsoleId');
if (sdConsoleElement !== null)
{
sdConsoleElement.innerHTML += "<br/>" + msg;
return true;
}
return false;
};
SD.console.debug = function(msg, debugLevel)
{
if (debugLevel > SD.DEBUG_LEVEL)
{
return false;
}
return SD.console.log("Debug:"+msg);
};
SD.console.warn = function(msg)
{
if (typeof(console) !== 'undefined')
{
if (typeof(console.warn) === 'function')
{
console.warn(msg);
}
}
return SD.console.log("Warn:"+msg);
};
SD.console.error = function(msg)
{
if (typeof(console) !== 'undefined')
{
if (typeof(console.error) === 'function')
{
console.error(msg);
}
}
if (SD.console.log("Error *** :"+msg))
{
return true;
}
// Notify the user
switch (SD.NOTIFY_METHOD)
{
case 'alert': alert("Error:"+msg); break;
case 'title': document.title = msg; break;
case 'status': window.status = msg; break;
}
return true;
};
////////////////////////////////////////////