Skip to content

Commit

Permalink
just fix the logging (#73468)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed Aug 6, 2022
1 parent 2db51aa commit d9df7c4
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/mono/wasm/runtime/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export function mono_wasm_trace_logger(log_domain_ptr: CharPtr, log_level_ptr: C
}
}

export function setup_proxy_console(id: string, originalConsole: Console, origin: string): void {
export function setup_proxy_console(id: string, console: any, origin: string): void {
function proxyConsoleMethod(prefix: string, func: any, asJson: boolean) {
return function (...args: any[]) {
try {
Expand Down Expand Up @@ -514,11 +514,14 @@ export function setup_proxy_console(id: string, originalConsole: Console, origin
};
}

const originalConsoleObj: any = originalConsole;
const originalConsole = {
log: console.log,
error: console.error
};
const methods = ["debug", "trace", "warn", "info", "error"];
for (const m of methods) {
if (typeof (originalConsoleObj[m]) !== "function") {
originalConsoleObj[m] = proxyConsoleMethod(`console.${m}: `, originalConsole.log, false);
if (typeof (console[m]) !== "function") {
console[m] = proxyConsoleMethod(`console.${m}: `, originalConsole.log, false);
}
}

Expand Down Expand Up @@ -546,7 +549,7 @@ export function setup_proxy_console(id: string, originalConsole: Console, origin

// redirect output early, so that when emscripten starts it's already redirected
for (const m of ["log", ...methods])
originalConsoleObj[m] = proxyConsoleMethod(`console.${m}`, send, true);
console[m] = proxyConsoleMethod(`console.${m}`, send, true);
}

type CallDetails = {
Expand Down

0 comments on commit d9df7c4

Please sign in to comment.