|
1 | 1 | import * as nodeConsole from 'console'; |
2 | 2 | import * as nodeUtil from 'util'; |
3 | 3 | import chalk from 'chalk'; |
| 4 | +import redent from 'redent'; |
4 | 5 |
|
5 | 6 | export const logger = { |
6 | 7 | debug(message: any, ...args: any[]) { |
7 | | - const output = nodeUtil.format('RNTL: ', message, ...args); |
| 8 | + const output = formatMessage('●', message, ...args); |
8 | 9 | nodeConsole.debug(chalk.dim(output)); |
9 | 10 | }, |
10 | 11 |
|
11 | 12 | info(message: any, ...args: any[]) { |
12 | | - const output = nodeUtil.format('RNTL: ', message, ...args); |
| 13 | + const output = formatMessage('●', message, ...args); |
13 | 14 | nodeConsole.info(output); |
14 | 15 | }, |
15 | 16 |
|
16 | 17 | warn(message: any, ...args: any[]) { |
17 | | - const output = nodeUtil.format('RNTL: ', message, ...args); |
| 18 | + const output = formatMessage('▲', message, ...args); |
18 | 19 | nodeConsole.warn(chalk.yellow(output)); |
19 | 20 | }, |
20 | 21 |
|
21 | 22 | error(message: any, ...args: any[]) { |
22 | | - const output = nodeUtil.format('RNTL: ', message, ...args); |
| 23 | + const output = formatMessage('■', message, ...args); |
23 | 24 | nodeConsole.error(chalk.red(output)); |
24 | 25 | }, |
25 | 26 | }; |
| 27 | + |
| 28 | +function formatMessage(symbol: string, message: any, ...args: any[]) { |
| 29 | + const formatted = nodeUtil.format(message, ...args); |
| 30 | + const indented = redent(formatted, 4); |
| 31 | + return ` ${symbol} ${indented.trimStart()}\n`; |
| 32 | +} |
0 commit comments