-
Notifications
You must be signed in to change notification settings - Fork 278
Expand file tree
/
Copy pathlogger.ts
More file actions
39 lines (33 loc) · 1.09 KB
/
logger.ts
File metadata and controls
39 lines (33 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import * as nodeConsole from 'console';
import pc from 'picocolors';
import redent from 'redent';
import * as nodeUtil from 'util';
export const _console = {
debug: nodeConsole.debug,
info: nodeConsole.info,
warn: nodeConsole.warn,
error: nodeConsole.error,
};
export const logger = {
debug(message: unknown, ...args: unknown[]) {
const output = formatMessage('●', message, ...args);
_console.debug(pc.dim(output));
},
info(message: unknown, ...args: unknown[]) {
const output = formatMessage('●', message, ...args);
_console.info(output);
},
warn(message: unknown, ...args: unknown[]) {
const output = formatMessage('▲', message, ...args);
_console.warn(pc.yellow(output));
},
error(message: unknown, ...args: unknown[]) {
const output = formatMessage('■', message, ...args);
_console.error(pc.red(output));
},
};
function formatMessage(symbol: string, message: unknown, ...args: unknown[]) {
const formatted = nodeUtil.format(message, ...args);
const indented = redent(formatted, 4);
return ` ${symbol} ${indented.trimStart()}\n`;
}