-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path8-class.js
More file actions
30 lines (24 loc) · 561 Bytes
/
Copy path8-class.js
File metadata and controls
30 lines (24 loc) · 561 Bytes
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
'use strict';
class Logger {
constructor(kind) {
this.color = Logger.colors[kind] || Logger.colors.info;
}
log(s) {
const date = new Date().toISOString();
console.log(this.color + date + '\t' + s);
}
}
Logger.colors = {
warning: '\x1b[1;33m',
error: '\x1b[0;31m',
info: '\x1b[1;37m',
};
// Usage
const warning = new Logger('warning');
const error = new Logger('error');
const debug = new Logger('debug');
const slow = new Logger('slow');
slow.log('I am slow logger');
warning.log('Hello');
error.log('World');
debug.log('Bye!');