Last change
on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
735 bytes
|
Line | |
---|
1 | import chalk from 'chalk';
|
---|
2 |
|
---|
3 | const LOG_LEVELS = ['trace', 'debug', 'info', 'warn', 'error', 'silent'];
|
---|
4 |
|
---|
5 | export 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 |
|
---|
29 | export 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.