limit electron logs length
This commit is contained in:
1 parent
cdf37997bf
commit
a26cd9df98
5 files changed
+47
-15
No files matched your search
@@ -8,6 +8,10 @@ export const CALL_CREATOR_INJECT_DELAY_MS = 1000;
|
||||
export const BOT_POLL_RETRY_DELAY_MS = 1000;
|
||||
export const BOT_POLL_WAIT_SECONDS = 25;
|
||||
|
||||
export const MAX_LOG_CHARS = 400000;
|
||||
export const LOG_TRIM_KEEP_CHARS = 200000;
|
||||
export const HOOK_LOG_BUFFER_LIMIT = 500;
|
||||
|
||||
export const VK_API_VERSION = '5.131';
|
||||
export const VK_API_BASE_URL = 'https://api.vk.ru/method';
|
||||
export const VK_IM_URL = 'https://vk.ru/im';
|
||||
@@ -88,7 +92,14 @@ export const LOG_CAPTURE_SNIPPET = [
|
||||
'console.log=function(){',
|
||||
'_ol.apply(null,arguments);',
|
||||
"var m=Array.prototype.slice.call(arguments).join(' ');",
|
||||
"if(m.indexOf('[HOOK]')!==-1)window.__hookLogs.push(m)",
|
||||
"if(m.indexOf('[HOOK]')!==-1){",
|
||||
'window.__hookLogs.push(m);',
|
||||
'if(window.__hookLogs.length>' +
|
||||
HOOK_LOG_BUFFER_LIMIT +
|
||||
')window.__hookLogs.splice(0,window.__hookLogs.length-' +
|
||||
HOOK_LOG_BUFFER_LIMIT +
|
||||
')',
|
||||
'}',
|
||||
'}}',
|
||||
].join('');
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,8 +59,18 @@ function refreshPlatformHint() {
|
||||
linkInput.addEventListener('input', refreshPlatformHint);
|
||||
refreshPlatformHint();
|
||||
|
||||
const MAX_LOG_CHARS = 400000;
|
||||
const LOG_TRIM_KEEP_CHARS = 200000;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
function appendLog(text: string) {
|
||||
logEl.textContent += text;
|
||||
logEl.textContent = trimLogText((logEl.textContent || '') + text);
|
||||
logEl.scrollTop = logEl.scrollHeight;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user