refactor: escalate severe to electron

This commit is contained in:
Carlos Valente
2024-06-10 07:54:31 +02:00
committed by Carlos Valente
parent d41cd78f2e
commit 8742b790f3
3 changed files with 21 additions and 7 deletions
+9 -1
View File
@@ -8,19 +8,26 @@ import { consoleRed } from '../utils/console.js';
class Logger {
private queue: Log[];
private escalateErrorFn: (error: string) => void | null;
constructor() {
this.queue = [];
this.escalateErrorFn = null;
}
/**
* Enabling setup logger after init
*/
init() {
init(escalateErrorFn: (error: string) => void) {
this.queue.forEach((log) => {
this._push(log);
});
this.queue = [];
// we only get this when running in electron
if (escalateErrorFn) {
this.escalateErrorFn = escalateErrorFn;
}
}
private addToQueue(log: Log) {
@@ -105,6 +112,7 @@ class Logger {
*/
crash(origin: string, text: string) {
this.emit(LogLevel.Severe, origin, text);
this.escalateErrorFn?.(text);
}
/**