create consolex class for remote logging

This commit is contained in:
evanpelle
2024-12-18 11:50:31 -08:00
parent d0d5652b53
commit 642d5dc4ca
7 changed files with 52 additions and 70 deletions
+34
View File
@@ -0,0 +1,34 @@
import { EventBus } from "./EventBus"
import { LogSeverity } from "./Schemas"
import { SendLogEvent } from "../client/Transport"
export const consolex = {
log: console.log,
warn: console.warn,
error: console.error
}
let inited = false
// Only call this in client/browser!
export function initRemoteSender(eventBus: EventBus) {
if (inited) {
return
}
inited = true
consolex.log = (...args: any[]): void => {
console.log(...args);
eventBus.emit(new SendLogEvent(LogSeverity.Info, args.join(' ')))
}
consolex.warn = (...args: any[]): void => {
console.warn(...args);
eventBus.emit(new SendLogEvent(LogSeverity.Warn, args.join(' ')))
}
consolex.error = (...args: any[]): void => {
console.error(...args);
eventBus.emit(new SendLogEvent(LogSeverity.Error, args.join(' ')))
}
}