43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
"use strict";
|
|
|
|
/* global console: false */
|
|
|
|
/**
|
|
* Reporter that handles the reporting of logs, warnings and errors.
|
|
* @public
|
|
* @param {boolean} quiet Tells if the reporter should be quiet or not.
|
|
*/
|
|
module.exports = function(quiet) {
|
|
function noop() {
|
|
//Does nothing.
|
|
}
|
|
|
|
var reporter = {
|
|
log: noop,
|
|
warn: noop,
|
|
error: noop
|
|
};
|
|
|
|
if(!quiet && window.console) {
|
|
var attachFunction = function(reporter, name) {
|
|
//The proxy is needed to be able to call the method with the console context,
|
|
//since we cannot use bind.
|
|
reporter[name] = function reporterProxy() {
|
|
var f = console[name];
|
|
if (f.apply) { //IE9 does not support console.log.apply :)
|
|
f.apply(console, arguments);
|
|
} else {
|
|
for (var i = 0; i < arguments.length; i++) {
|
|
f(arguments[i]);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
attachFunction(reporter, "log");
|
|
attachFunction(reporter, "warn");
|
|
attachFunction(reporter, "error");
|
|
}
|
|
|
|
return reporter;
|
|
}; |