/
console-logger.js
63 lines (52 loc) · 1.25 KB
/
console-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
import chalk from 'chalk';
import moment from 'moment';
export default class ConsoleLogger {
constructor (options) {
options = Object.assign({
muted: false,
mode: mode.smart
}, options);
this.mode = options.mode;
this.muted = options.muted;
if (options.instance) {
options.instance.on('log', this.log);
options.instance.on('separator', this.separator);
}
}
/**
* @param id
* @param level
* @param messages
*/
log (id, level, messages) {
let string = `${modes[this.mode][level]} ${id} ${messages}`;
if (!this.muted) console.log(string);
return string;
}
/**
* @param id
* @param level
* @param messages
*/
separator (id, level, messages) {
let string = `${modes[this.mode][level]} ${id} ${messages}`;
if (!this.muted) console.log(string);
return string;
}
}
let modes = [
['DEBUG','INFO','NOTICE','WARNING','ERROR','CRITICAL','ALERT','EMERGENCY','TIME'],
['EMER','ALER','CRIT','ERRO','WARN','NOTI','INFO','DEBU','TIME'],
['DBUG','INFO','NOTC','WRNG','RROR','CRTC','ALRT','MRGC','TIME'],
['EM','AL','CR','ER','WA','NO','IN','DE','TI'],
['1','2','3','4','5','6','7','8','T'],
['M','A','C','R','W','N','I','D','T']
];
export let mode = {
full: 0,
short: 1,
smart: 2,
tiny: 3,
numbers: 4,
single: 5
};