Skip to content

Instantly share code, notes, and snippets.

@x86ed
Created March 29, 2012 18:20
Show Gist options
  • Save x86ed/2241495 to your computer and use it in GitHub Desktop.
Save x86ed/2241495 to your computer and use it in GitHub Desktop.
debug msg
function Debug(){// prevents console.logs from ending up in the code when debugging, YAY!
var typeLog = typeof(typeLog) != 'undefined' ? typeLog : "log";
//allows for an optional hrd coded caller argument
var caller = typeof(caller) != 'undefined' ? caller : this.caller;
this.debugMode = false;
function enable(value){
this.debugMode = value;
return this.debugMode;
};
function alertThis(massage,typeLog,caller){
if(this.debugMode){
alert(massage);
}
};
function log(massage,typeLog,caller){
if(this.debugMode){
var outputName = caller.name?caller.name + "::":"";
output = outputName + massage;
try {
console[typeLog](output);
}
catch(e) {
try {
opera.postError(output);
}
catch(e){
alert(output);
}
}
}
if(typeof(console) === 'undefined') {
console = {}
console.log = console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
}
}
return {
enable: enable,
alertThis: alertThis,
log: log
}
}
// & if you want to get really crazy:
Function.prototype.debug = new Debug;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment