mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-03 07:36:41 +02:00
Merge pull request #1144 from mermaid-js/other/1143_utilze_browser_console_object_better
#1143 Fixing up the color output of the logger
This commit is contained in:
@@ -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} : `;
|
||||
};
|
||||
|
Reference in New Issue
Block a user