MCPcopy Create free account
hub / github.com/GCWing/BitFun / installWebviewConsoleForward

Function installWebviewConsoleForward

src/web-ui/src/shared/utils/logger.ts:93–160  ·  view source on GitHub ↗

* Patch `console.*` so messages also go through `tauri_plugin_log` (webview target → webview.log).

()

Source from the content-addressed store, hash-verified

91 * Patch `console.*` so messages also go through `tauri_plugin_log` (webview target → webview.log).
92 */
93function installWebviewConsoleForward(): void {
94 if (!isTauri || typeof window === 'undefined') return;
95 const w = window as unknown as Record<string, boolean | undefined>;
96 if (w[CONSOLE_FORWARD_INSTALLED]) return;
97
98 const c = window.console;
99 const orig = {
100 log: c.log.bind(c),
101 debug: c.debug.bind(c),
102 info: c.info.bind(c),
103 warn: c.warn.bind(c),
104 error: c.error.bind(c),
105 trace: c.trace.bind(c),
106 };
107
108 const forward = (
109 kind: 'log' | 'debug' | 'info' | 'warn' | 'error' | 'trace',
110 args: unknown[]
111 ) => {
112 if ((CONSOLE_KIND_LEVEL[kind] ?? LogLevel.INFO) < consoleForwardMinLevel) return;
113 const msg = `[console] ${formatConsoleArgs(args)}`;
114 switch (kind) {
115 case 'log':
116 case 'info':
117 void tauriInfo(msg).catch(() => {});
118 break;
119 case 'debug':
120 void tauriDebug(msg).catch(() => {});
121 break;
122 case 'trace':
123 void tauriTrace(msg).catch(() => {});
124 break;
125 case 'warn':
126 void tauriWarn(msg).catch(() => {});
127 break;
128 case 'error':
129 void tauriError(msg).catch(() => {});
130 break;
131 }
132 };
133
134 c.log = (...args: unknown[]) => {
135 forward('log', args);
136 orig.log(...args);
137 };
138 c.info = (...args: unknown[]) => {
139 forward('info', args);
140 orig.info(...args);
141 };
142 c.debug = (...args: unknown[]) => {
143 forward('debug', args);
144 orig.debug(...args);
145 };
146 c.trace = (...args: unknown[]) => {
147 forward('trace', args);
148 orig.trace(...args);
149 };
150 c.warn = (...args: unknown[]) => {

Callers 1

bootstrapLoggerFunction · 0.85

Calls 8

bindMethod · 0.80
debugMethod · 0.80
traceMethod · 0.80
warnMethod · 0.80
forwardFunction · 0.70
logMethod · 0.45
infoMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected