- Converte logger.js para IIFE (remove export) - Converte state.js para IIFE (remove export) - Remove imports de app.js - Corrige referências aos scripts de teste removidos - Adiciona scripts de teste corretos
59 lines
1.4 KiB
JavaScript
59 lines
1.4 KiB
JavaScript
/**
|
|
* Logger com níveis de debug
|
|
* Substitui console.log dispersos pelo código
|
|
*/
|
|
var Logger = (function() {
|
|
var LEVELS = {
|
|
debug: 0,
|
|
info: 1,
|
|
warn: 2,
|
|
error: 3
|
|
};
|
|
|
|
var currentLevel = LEVELS.info;
|
|
|
|
function setLevel(level) {
|
|
if (LEVELS[level] !== undefined) {
|
|
currentLevel = LEVELS[level];
|
|
}
|
|
}
|
|
|
|
function shouldLog(level) {
|
|
return LEVELS[level] >= currentLevel;
|
|
}
|
|
|
|
function formatMessage(level) {
|
|
var timestamp = new Date().toISOString().slice(11, 19);
|
|
return '[' + timestamp + '] [' + level.toUpperCase() + ']';
|
|
}
|
|
|
|
return {
|
|
debug: function() {
|
|
if (shouldLog('debug')) console.debug(formatMessage('debug'), arguments);
|
|
},
|
|
|
|
info: function() {
|
|
if (shouldLog('info')) console.info(formatMessage('info'), arguments);
|
|
},
|
|
|
|
warn: function() {
|
|
if (shouldLog('warn')) console.warn(formatMessage('warn'), arguments);
|
|
},
|
|
|
|
error: function() {
|
|
if (shouldLog('error')) console.error(formatMessage('error'), arguments);
|
|
},
|
|
|
|
setLevel: setLevel,
|
|
|
|
enableDebug: function() {
|
|
setLevel('debug');
|
|
},
|
|
|
|
disableDebug: function() {
|
|
setLevel('info');
|
|
}
|
|
};
|
|
})();
|
|
|
|
window.Logger = Logger; |