Skip to content

Commit

Permalink
Merge pull request #1144 from mermaid-js/other/1143_utilze_browser_co…
Browse files Browse the repository at this point in the history
…nsole_object_better

#1143 Fixing up the color output of the logger
  • Loading branch information
knsv committed Dec 15, 2019
2 parents 0544dbe + 26fac95 commit dddd5af
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/logger.js
Expand Up @@ -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} : `;
};

0 comments on commit dddd5af

Please sign in to comment.