-
-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy path7-prototype.js
More file actions
28 lines (22 loc) · 563 Bytes
/
Copy path7-prototype.js
File metadata and controls
28 lines (22 loc) · 563 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
'use strict';
function Logger(kind) {
this.color = Logger.colors[kind] || Logger.colors.info;
}
Logger.colors = {
warning: '\x1b[1;33m',
error: '\x1b[0;31m',
info: '\x1b[1;37m',
};
Logger.prototype.log = function(s) {
const date = new Date().toISOString();
console.log(this.color + date + '\t' + s);
};
// 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!');