forked from ruimarinho/gsts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
65 lines (49 loc) · 1.08 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
65
/**
* Module dependencies.
*/
const ora = require('ora');
const util = require('util')
/**
* Logger with support for TTY detection.
*/
class Logger {
constructor(verbose, isTTY) {
this.isTTY = isTTY;
this.verbose = verbose;
this.ora = ora({ isEnabled: this.isTTY });
}
format(...args) {
if (!this.isTTY) {
args.unshift(new Date().toISOString())
}
return util.format(...args);
}
start(...args) {
if (!this.isTTY) {
return;
}
return this.ora.start(...args);
}
stop(...args) {
return this.ora.stop(...args);
}
debug(...args) {
if (!this.verbose) {
return;
}
return this.ora.info(this.format(...args));
}
info(...args) {
return this.ora.info(this.format(...args));
}
warn(...args) {
return this.ora.warn(this.format(...args));
}
error(...args) {
return this.ora.fail(this.format(...args));
}
succeed(...args) {
return this.ora.succeed(this.format(...args));
}
}
module.exports = Logger;