/
logger.js
73 lines (69 loc) · 1.32 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
66
67
68
69
70
71
72
73
var chalk;
try {
chalk = require('chalk');
} catch (e) {
// do nothing
}
var boxen;
try {
boxen = require('boxen');
} catch (e) {
// do nothing
}
var stripAnsi;
try {
stripAnsi = require('strip-ansi');
} catch (e) {
// do nothing
}
var logger = {
chalkProxy: function (fnName, msg) {
if (chalk && chalk[fnName]) {
return chalk[fnName](msg);
} else {
return msg;
}
},
stripAnsi: function (msg) {
if (stripAnsi) {
return stripAnsi(msg);
} else {
return msg;
}
},
boxen: function (msg, options) {
if (boxen) {
return boxen(msg, options);
} else {
return msg;
}
},
log: function (msg) {
console.log(msg);
},
info: function (msg) {
if (chalk) {
msg = chalk.blue(msg);
}
console.log(msg);
},
warn: function (msg) {
if (chalk) {
msg = chalk.yellow(msg);
}
console.log(msg);
},
error: function (msg) {
if (chalk) {
msg = chalk.red(msg);
}
console.log(msg);
},
success: function (msg) {
if (chalk) {
msg = chalk.green(msg);
}
console.log(msg);
}
};
module.exports = logger;