maxLevel: 0,
consoleLevels: [
[],
console.debug || [],
console.log || [],
console.info || [],
console.notify || [],
console.warn || [],
console.error || [],
console.fatal || []
],
levelNames: {},
setLevel: function (l) {
var number;
if (typeof l == "string") {
number = this.levels[l];
if (number === undefined) {
throw new Error("Tried to set Console level to unknown level string: " + l);
}
l = number;
}
if (typeof l == "function") {
number = this.consoleLevels.indexOf(l);
if (number == -1) {
throw new Error("Tried to set Console level based on unknown console function: " + l);
}
l = number;
}
if (typeof l == "number") {
if (l < 0) {
throw new Error("Console level must be 0 or larger: " + l);
} else if (l > this.maxLevel) {
throw new Error("Console level must be " + this.maxLevel + " or smaller: " + l);
}
}
this.level = l;
},
write: function (level) {
try {
this.messages.push([
Date.now(),
level,
this._stringify(Array.prototype.slice.call(arguments, 1))
]);
} catch (e) {
console.warn("Error stringifying argument:", e);
}
if (level != "suppress" && this.level <= level) {
var method = console[this.levelNames[level]];
if (! method) {
method = console.log;
}
method.apply(console, Array.prototype.slice.call(arguments, 1));
}
},
suppressedWrite: function () {
this.write.apply(this, ["suppress"].concat(Array.prototype.slice.call(arguments)));
},
trace: function (level) {
level = level || 'log';
if (console.trace) {
level = "suppressedWrite";
}
try {
throw new Error();
} catch (e) {