limit electron logs length
This commit is contained in:
1 parent
cdf37997bf
commit
a26cd9df98
5 files changed
+47
-15
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { Platform, Bridge, LogPanel, TunnelMode, Webview } from '../types';
|
||||
import { SESSION_PARTITION, HOOK_POLL_INTERVAL_MS, CALL_CREATOR_INJECT_DELAY_MS, USER_AGENT } from '../constants';
|
||||
import { RendererTabManager } from './tab-manager';
|
||||
import { appendLogElement } from './log-buffer';
|
||||
|
||||
declare const window: Window & { bridge: Bridge };
|
||||
|
||||
@@ -260,11 +261,7 @@ export function startHookLogPoller(tm: RendererTabManager): void {
|
||||
.then((logs: string[]) => {
|
||||
if (!logs.length) return;
|
||||
const el = document.getElementById('hookLog')!;
|
||||
logs.forEach((msg) => {
|
||||
if (el.textContent!.length > 0) el.textContent += '\n';
|
||||
el.textContent += msg.replace('[HOOK] ', '');
|
||||
});
|
||||
el.scrollTop = el.scrollHeight;
|
||||
appendLogElement(el, logs.map((msg) => msg.replace('[HOOK] ', '')).join('\n'));
|
||||
})
|
||||
.catch(() => {});
|
||||
}, HOOK_POLL_INTERVAL_MS);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { MAX_LOG_CHARS, LOG_TRIM_KEEP_CHARS } from '../constants';
|
||||
|
||||
export function trimLogText(text: string): string {
|
||||
if (text.length <= MAX_LOG_CHARS) return text;
|
||||
const cut = text.length - LOG_TRIM_KEEP_CHARS;
|
||||
const newline = text.indexOf('\n', cut);
|
||||
return text.slice(newline === -1 ? cut : newline + 1);
|
||||
}
|
||||
|
||||
export function appendLogText(text: string, msg: string): string {
|
||||
return trimLogText(text ? text + '\n' + msg : msg);
|
||||
}
|
||||
|
||||
export function appendLogElement(el: HTMLElement, msg: string): void {
|
||||
el.textContent = appendLogText(el.textContent || '', msg);
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
HeadlessStartArgs,
|
||||
} from '../types';
|
||||
import { HeadlessLogMarker } from '../constants';
|
||||
import { appendLogText, appendLogElement, trimLogText } from './log-buffer';
|
||||
|
||||
declare const window: Window & { bridge: Bridge };
|
||||
|
||||
@@ -160,8 +161,8 @@ export class RendererTabManager {
|
||||
if (this.activeTabId && this.tabs[this.activeTabId]) {
|
||||
const relayEl = document.getElementById('relayLog');
|
||||
const hookEl = document.getElementById('hookLog');
|
||||
if (relayEl) this.tabs[this.activeTabId].relayLogs = relayEl.textContent || '';
|
||||
if (hookEl) this.tabs[this.activeTabId].hookLogs = hookEl.textContent || '';
|
||||
if (relayEl) this.tabs[this.activeTabId].relayLogs = trimLogText(relayEl.textContent || '');
|
||||
if (hookEl) this.tabs[this.activeTabId].hookLogs = trimLogText(hookEl.textContent || '');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,16 +184,12 @@ export class RendererTabManager {
|
||||
appendRelayLog(tabId: string, msg: string): void {
|
||||
const tab = this.tabs[tabId];
|
||||
if (!tab) return;
|
||||
tab.relayLogs += (tab.relayLogs ? '\n' : '') + msg;
|
||||
tab.relayLogs = appendLogText(tab.relayLogs, msg);
|
||||
let rendered = false;
|
||||
if (tab.headless) rendered = this.parseHeadlessLog(tabId, msg);
|
||||
if (tabId === this.activeTabId && !rendered) {
|
||||
const el = document.getElementById('relayLog');
|
||||
if (el) {
|
||||
if (el.textContent!.length > 0) el.textContent += '\n';
|
||||
el.textContent += msg;
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
if (el) appendLogElement(el, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user