/
Logger.js
39 lines (31 loc) · 839 Bytes
/
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
const chalk = new (require('chalk')).constructor({enabled: true});
class Logger {
constructor(options = {}) {
this.showDebug = !!options.showDebug;
this.onlyErrors = !!options.onlyErrors;
this.timestamps = !!options.timestamps
}
get timestamp() {
return this.timestamps ? `[${new Date().toLocaleString()}] ` : '';
}
log() {
if (!this.onlyErrors)
console.log(this.timestamp + Array.prototype.join.call(arguments, ' '));
}
info() {
if (!this.onlyErrors)
console.info(this.timestamp + chalk.cyan(...arguments));
}
debug() {
if (this.showDebug)
console.log(this.timestamp + chalk.gray(...arguments));
}
warn() {
if (!this.onlyErrors)
console.warn(this.timestamp + chalk.yellow(...arguments));
}
error() {
console.error(this.timestamp + chalk.red(...arguments));
}
}
module.exports = Logger;