-
Notifications
You must be signed in to change notification settings - Fork 2
/
Logger.js
35 lines (30 loc) · 886 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
// simple logger
function Logger(outputChannel, verbose) {
this.outputChannel = outputChannel;
this.verbose = verbose;
}
function log(message, severity) {
// only log error messages unless verbose
if (!this.verbose && severity !== 'error') {
return;
}
if (this.outputChannel && message) {
const prefix = `[${severity.toUpperCase()}] `;
message = message.replace(/(^|\n)/g, `$1${prefix}`);
// don't repeat identical messages (reduces some noise)
if (this.lastMessage !== message) {
this.lastMessage = message;
this.outputChannel.appendLine(message);
}
}
}
Logger.prototype.error = function(message) {
log.call(this, message, 'error');
};
Logger.prototype.warn = function(message) {
log.call(this, message, 'warning');
};
Logger.prototype.info = function(message) {
log.call(this, message, 'info');
};
module.exports = Logger;