mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-01 22:33:30 +00:00
create consolex class for remote logging
This commit is contained in:
@@ -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(' ')))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user