-
Notifications
You must be signed in to change notification settings - Fork 5
/
logger.js
64 lines (52 loc) · 1.25 KB
/
logger.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import chalk from "chalk";
class Logger {
constructor(verbosity = 0) {
this.stderr = [];
this.stdout = [];
this.verbosity = verbosity;
}
setVerbosity(verbosity) {
this.verbosity = verbosity;
}
writeOut(message) {
process.stdout.write(message + "\n");
}
writeErr(message) {
process.stderr.write(message + "\n");
}
resetStderr() {
this.stderr = [];
}
resetStdout() {
this.stdout = [];
}
log(message) {
this.stdout.push(message);
this.writeOut(message);
}
info(message) {
const formatedMessage = chalk.blue.bold("ℹ ") + message;
this.stderr.push(formatedMessage);
this.writeErr(formatedMessage);
}
debug(message) {
const formatedMessage = chalk.blue.bold("ℹ ") + message;
this.stderr.push(formatedMessage);
if (this.verbosity === 0) {
return;
}
this.writeErr(formatedMessage);
}
error(message) {
const formatedMessage = chalk.red.bold("✖ ") + message;
this.stderr.push(formatedMessage);
this.writeErr(formatedMessage);
}
success(message) {
const formatedMessage = chalk.green.bold("✔ ") + message;
this.stderr.push(formatedMessage);
this.writeErr(formatedMessage);
}
}
const logger = new Logger();
export default logger;