- Adiciona validação em calcularCustoTotal, calcularSecagem, calcularCEV, calcularCisalhamento, calcularPreaquecimento - Cria Logger com níveis (debug, info, warn, error) - Consolida 5 arquivos de teste em 1 (test-suite.js) - Adiciona safe DOM access em funções de cálculo
60 lines
1.5 KiB
JavaScript
60 lines
1.5 KiB
JavaScript
/**
|
|
* Logger com níveis de debug
|
|
* Substitui console.log dispersos pelo código
|
|
*/
|
|
const Logger = (function() {
|
|
const LEVELS = {
|
|
debug: 0,
|
|
info: 1,
|
|
warn: 2,
|
|
error: 3
|
|
};
|
|
|
|
let currentLevel = LEVELS.info;
|
|
|
|
function setLevel(level) {
|
|
if (LEVELS[level] !== undefined) {
|
|
currentLevel = LEVELS[level];
|
|
}
|
|
}
|
|
|
|
function shouldLog(level) {
|
|
return LEVELS[level] >= currentLevel;
|
|
}
|
|
|
|
function formatMessage(level, ...args) {
|
|
const timestamp = new Date().toISOString().slice(11, 19);
|
|
return `[${timestamp}] [${level.toUpperCase()}]`;
|
|
}
|
|
|
|
return {
|
|
debug: function(...args) {
|
|
if (shouldLog('debug')) console.debug(formatMessage('debug', ...args), ...args);
|
|
},
|
|
|
|
info: function(...args) {
|
|
if (shouldLog('info')) console.info(formatMessage('info', ...args), ...args);
|
|
},
|
|
|
|
warn: function(...args) {
|
|
if (shouldLog('warn')) console.warn(formatMessage('warn', ...args), ...args);
|
|
},
|
|
|
|
error: function(...args) {
|
|
if (shouldLog('error')) console.error(formatMessage('error', ...args), ...args);
|
|
},
|
|
|
|
setLevel: setLevel,
|
|
|
|
enableDebug: function() {
|
|
setLevel('debug');
|
|
},
|
|
|
|
disableDebug: function() {
|
|
setLevel('info');
|
|
}
|
|
};
|
|
})();
|
|
|
|
window.Logger = Logger;
|
|
export default Logger; |