-
Notifications
You must be signed in to change notification settings - Fork 12
/
logger.js
41 lines (34 loc) · 945 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
36
37
38
39
40
41
import fs from 'fs';
export class Logger {
constructor() {
if (process.versions.electron) {
this._htmlLogger = document.getElementById('logger');
}
this._logs = [];
}
logInfo(msg) {
this.log(msg);
}
logError(msg) {
this.log(msg, 'color: red;')
}
log(msg, style) {
if (!msg) return;
if (this._htmlLogger) {
this._htmlLogger
.insertAdjacentHTML('beforeend', `\n <p style="${style || 'color: black;'}">${msg}</p>`);
// Scroll to bottom
this._htmlLogger.scrollTop = this._htmlLogger.scrollHeight;
}else {
console.log(msg);
}
this._logs.push(msg);
}
exportLogs(path) {
return new Promise((resolve, reject) => {
fs.writeFile(path, this._logs.join('\n'), (err) => {
resolve();
});
});
}
}