2015-01-18 13:00:58 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Logger
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
var LOGGER = (function() {
|
2018-11-20 22:18:49 +00:00
|
|
|
let LOG_LEVEL = 'info';
|
2015-01-18 13:00:58 +00:00
|
|
|
|
|
|
|
function fnDebug() {
|
|
|
|
if (LOG_LEVEL == 'debug') {
|
2018-11-20 22:18:49 +00:00
|
|
|
_log('DEBUG', arguments);
|
2015-01-18 13:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function fnInfo() {
|
|
|
|
if (LOG_LEVEL == 'debug' || LOG_LEVEL === 'info') {
|
2018-11-20 22:18:49 +00:00
|
|
|
_log('INFO', arguments);
|
2015-01-18 13:00:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function fnError() {
|
2018-11-20 22:18:49 +00:00
|
|
|
_log('ERROR', arguments);
|
2015-01-18 13:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function fnSetLevel(level) {
|
|
|
|
LOG_LEVEL = level;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------- privates ----------------------------------------- //
|
|
|
|
|
|
|
|
function _log(level, args) {
|
|
|
|
// Prepends log level to things that will be logged
|
|
|
|
args = Array.prototype.slice.call(args);
|
2018-11-20 22:18:49 +00:00
|
|
|
args.unshift(`[${level}]`);
|
2019-01-05 14:48:14 +00:00
|
|
|
try {
|
|
|
|
console.log.apply(this, args);
|
|
|
|
} catch (e) {
|
|
|
|
// do nothing
|
2015-01-18 13:00:58 +00:00
|
|
|
}
|
2018-11-20 22:18:49 +00:00
|
|
|
}
|
2015-01-18 13:00:58 +00:00
|
|
|
|
|
|
|
// ---------------------------------- expose publics here ------------------------------------ //
|
|
|
|
|
|
|
|
return {
|
|
|
|
debug: fnDebug,
|
|
|
|
info: fnInfo,
|
|
|
|
error: fnError,
|
|
|
|
setLevel: fnSetLevel
|
|
|
|
};
|
2018-11-20 22:18:49 +00:00
|
|
|
})();
|