From 26fac9507e17db032b88b00c3eef24dfc09bb5a9 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Sun, 15 Dec 2019 09:50:24 +0100 Subject: [PATCH] #1143 Fixing up the color putput of the logger --- src/logger.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/logger.js b/src/logger.js index 5de9e320a..e69af084c 100644 --- a/src/logger.js +++ b/src/logger.js @@ -23,23 +23,34 @@ export const setLogLevel = function(level) { logger.error = () => {}; logger.fatal = () => {}; if (level <= LEVELS.fatal) { - logger.fatal = console.log.bind(console, '\x1b[35m', format('FATAL')); + logger.fatal = console.error + ? console.error.bind(console, format('FATAL'), 'color: orange') + : console.log.bind(console, '\x1b[35m', format('FATAL')); } if (level <= LEVELS.error) { - logger.error = console.log.bind(console, '\x1b[31m', format('ERROR')); + logger.error = console.error + ? console.error.bind(console, format('ERROR'), 'color: orange') + : console.log.bind(console, '\x1b[31m', format('ERROR')); } if (level <= LEVELS.warn) { - logger.warn = console.log.bind(console, `\x1b[33m`, format('WARN')); + logger.warn = console.warn + ? console.warn.bind(console, format('WARN'), 'color: orange') + : console.log.bind(console, `\x1b[33m`, format('WARN')); } if (level <= LEVELS.info) { - logger.info = console.log.bind(console, '\x1b[34m', format('INFO')); + logger.info = console.info + ? // ? console.info.bind(console, '\x1b[34m', format('INFO'), 'color: blue') + console.info.bind(console, format('INFO'), 'color: lightblue') + : console.log.bind(console, '\x1b[34m', format('INFO')); } if (level <= LEVELS.debug) { - logger.debug = console.log.bind(console, '\x1b[32m', format('DEBUG')); + logger.debug = console.debug + ? console.debug.bind(console, format('DEBUG'), 'color: lightgreen') + : console.log.bind(console, '\x1b[32m', format('DEBUG')); } }; const format = level => { - const time = moment().format('HH:mm:ss.SSS'); - return `${time} : ${level} : `; + const time = moment().format('ss.SSS'); + return `%c${time} : ${level} : `; };