mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-20 02:30:21 +00:00
send all logs from client to server and log them
This commit is contained in:
+27
-6
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user