refactor: validação de inputs e melhorias de código
- 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
This commit is contained in:
60
public/js/utils/logger.js
Normal file
60
public/js/utils/logger.js
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* 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;
|
||||
Reference in New Issue
Block a user