source: trip-planner-front/node_modules/critters/src/util.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 735 bytes
Line 
1import chalk from 'chalk';
2
3const LOG_LEVELS = ['trace', 'debug', 'info', 'warn', 'error', 'silent'];
4
5export const defaultLogger = {
6 trace(msg) {
7 console.trace(msg);
8 },
9
10 debug(msg) {
11 console.debug(msg);
12 },
13
14 warn(msg) {
15 console.warn(chalk.yellow(msg));
16 },
17
18 error(msg) {
19 console.error(chalk.bold.red(msg));
20 },
21
22 info(msg) {
23 console.info(chalk.bold.blue(msg));
24 },
25
26 silent() {}
27};
28
29export function createLogger(logLevel) {
30 const logLevelIdx = LOG_LEVELS.indexOf(logLevel);
31
32 return LOG_LEVELS.reduce((logger, type, index) => {
33 if (index >= logLevelIdx) {
34 logger[type] = defaultLogger[type];
35 } else {
36 logger[type] = defaultLogger.silent;
37 }
38 return logger;
39 }, {});
40}
Note: See TracBrowser for help on using the repository browser.