Added logger util and used in place of console log

This commit is contained in:
Joe Dowd
2020-08-21 15:27:41 +01:00
parent 5ac5c30fd6
commit 226197a827
11 changed files with 74 additions and 34 deletions

36
src/utils/logger.js Normal file
View File

@@ -0,0 +1,36 @@
const config = require('../config.js');
const levels = {
ERROR: "ERROR",
WARN: "WARN",
INFO: "INFO",
DEBUG: "DEBUG"
};
const settings = {
ERROR: true,
WARN: true,
INFO: false,
DEBUG: false
};
if (config.mode === 'development') {
settings.INFO = true;
settings.DEBUG = true;
}
function log(level, string) {
if (!!settings[level]) {
if (level.length === 4) {level = level + " "}; // ensure logs are aligned
console.log(level + " " + new Date().toISOString() + " : " + string);
}
}
module.exports = {
levels,
log,
error: (string) => {log(levels.ERROR, string)},
warn: (string) => {log(levels.WARN, string)},
info: (string) => {log(levels.INFO, string)},
debug: (string) => {log(levels.DEBUG, string)},
};