mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-12-15 04:32:27 +00:00
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
// Logger
|
||
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
var LOGGER = (function() {
|
||
|
|
||
|
var LOG_LEVEL = 'info';
|
||
|
|
||
|
function fnDebug() {
|
||
|
if (LOG_LEVEL == 'debug') {
|
||
|
_log("DEBUG", arguments);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function fnInfo() {
|
||
|
if (LOG_LEVEL == 'debug' || LOG_LEVEL === 'info') {
|
||
|
_log("INFO", arguments);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function fnError() {
|
||
|
_log("ERROR", arguments);
|
||
|
}
|
||
|
|
||
|
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);
|
||
|
args.unshift('['+level+']');
|
||
|
// Determine if there's a logger (console.log) available
|
||
|
var win = unsafeWindow || window;
|
||
|
var console = win.console;
|
||
|
if (console && console.log && console.log.apply) {
|
||
|
try {
|
||
|
console.log.apply(this, args);
|
||
|
} catch(e) {}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
// ---------------------------------- expose publics here ------------------------------------ //
|
||
|
|
||
|
return {
|
||
|
debug: fnDebug,
|
||
|
info: fnInfo,
|
||
|
error: fnError,
|
||
|
setLevel: fnSetLevel
|
||
|
};
|
||
|
})();
|