send all logs from client to server and log them

This commit is contained in:
Evan
2024-12-17 19:53:17 -08:00
parent 031f62c701
commit 94992e1144
7 changed files with 50 additions and 25 deletions
+27 -6
View File
@@ -1,16 +1,37 @@
import { EventBus } from "../core/EventBus"
import { LogSeverity } from "../core/Schemas"
import { SendLogEvent } from "./Transport"
export enum LogSeverity {
Info,
Warn,
Error
}
let inited = false
export function initializeLogSender(eventBus: EventBus) {
if (inited) {
return
}
inited = true
// Store original console methods
const originalLog = console.log
const originalWarn = console.warn
const originalError = console.error
const log = (msg: string): void => {
eventBus.emit(new SendLogEvent(LogSeverity.Info, msg))
console.log(msg)
originalLog.call(console, msg) // Use the original method
}
const warn = (msg: string): void => {
eventBus.emit(new SendLogEvent(LogSeverity.Warn, msg))
originalWarn.call(console, msg) // Use the original method
}
const error = (msg: string): void => {
eventBus.emit(new SendLogEvent(LogSeverity.Error, msg))
originalError.call(console, msg) // Use the original method
}
// Replace console methods
console.log = log
console.warn = warn
console.error = error
}