mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-20 07:49:43 +02:00

- JavaFX does not support lookbehind - (?) It also appears that named regex groups are also unsupported for both mermaid and javafx Update: - Fixed an issue where setLogLevel did not properly handle 'named' log levels - Backwards compatibility should be preserved, any/all %%{...}%% directives will be correctly processed by the grammar and properly ignored for any/all graph types that do not support them. - Multiline directives will render an error (as they should) if they are not accounted for in the .jison grammar
64 lines
1.7 KiB
JavaScript
64 lines
1.7 KiB
JavaScript
import moment from 'moment-mini';
|
|
//
|
|
export const LEVELS = {
|
|
debug: 1,
|
|
info: 2,
|
|
warn: 3,
|
|
error: 4,
|
|
fatal: 5
|
|
};
|
|
|
|
export const logger = {
|
|
debug: () => {},
|
|
info: () => {},
|
|
warn: () => {},
|
|
error: () => {},
|
|
fatal: () => {}
|
|
};
|
|
|
|
export const setLogLevel = function(level = 'fatal') {
|
|
if (isNaN(level)) {
|
|
level = level.toLowerCase();
|
|
if (LEVELS[level] !== undefined) {
|
|
level = LEVELS[level];
|
|
}
|
|
}
|
|
logger.trace = () => {};
|
|
logger.debug = () => {};
|
|
logger.info = () => {};
|
|
logger.warn = () => {};
|
|
logger.error = () => {};
|
|
logger.fatal = () => {};
|
|
if (level <= LEVELS.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.error
|
|
? console.error.bind(console, format('ERROR'), 'color: orange')
|
|
: console.log.bind(console, '\x1b[31m', format('ERROR'));
|
|
}
|
|
if (level <= LEVELS.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.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.debug
|
|
? console.debug.bind(console, format('DEBUG'), 'color: lightgreen')
|
|
: console.log.bind(console, '\x1b[32m', format('DEBUG'));
|
|
}
|
|
};
|
|
|
|
const format = level => {
|
|
const time = moment().format('ss.SSS');
|
|
return `%c${time} : ${level} : `;
|
|
};
|