-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.js
61 lines (45 loc) · 1.28 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
const chalk = require('chalk');
const moment = require('moment');
class Logger {
constructor(client, opts = {}) {
if(!opts) return null;
Object.defineProperty(this, 'client', {
value: client
});
}
log(message, opts = {}) {
this._write(message, { ...opts, type: 'LOG' });
}
info(message, opts = {}) {
this._write(message, { ...opts, type: 'INFO' });
}
warn(message, opts = {}) {
this._write(message, { ...opts, type: 'WARN' });
}
debug(message, opts = {}) {
this._write(message, { ...opts, type: 'DEBUG' });
}
error(message, opts = {}) {
this._write(message, { ...opts, type: 'ERROR' });
}
_write(string = '', { type }) {
const color = Constants.Colors[type] || Constants.Colors.NONE;
const header = `${chalk.hex(color)(`[${this.date}]`)}`;
console.log(`${header} : ${chalk.bold(`[${type}]`)} ${string}`); //eslint-disable-line
}
get date() {
return moment().format("MM/DD hh:mm:ss");
}
}
module.exports = Logger;
const Constants = {
Colors: {
NONE: 0x6e6e6e,
LOG: 0x5e97d1,
INFO: 0x5e97d1,
WARN: 0xe9d15f,
DEBUG: 0xc573d1,
ERROR: 0xe56060,
SUCCESS: 0x6ccf69
}
};