Optimize console log capture in production
Only capture log/info levels in dev builds or when verbose mode is explicitly enabled in Developer Mode. Always capture error/warn for bug tracking. Reduces GC/CPU overhead in production builds. Adds toggle in Settings > Developer Mode to enable verbose capture when debugging production issues.
This commit is contained in:
1 parent
51a24de9cb
commit
14e657e8af
6 files changed
+96
-9
No files matched your search
@@ -56,6 +56,11 @@
|
||||
type OfflineSettings
|
||||
} from '$lib/stores/offlineStore';
|
||||
import { showToast } from '$lib/stores/toastStore';
|
||||
import {
|
||||
enableVerboseCapture,
|
||||
disableVerboseCapture,
|
||||
isVerboseCaptureEnabled
|
||||
} from '$lib/stores/consoleLogStore';
|
||||
import {
|
||||
subscribe as subscribeTitleBar,
|
||||
getHideTitleBar,
|
||||
@@ -264,6 +269,7 @@
|
||||
let storageCollapsed = $state(true);
|
||||
let developerCollapsed = $state(true);
|
||||
let forceDmabuf = $state(false);
|
||||
let verboseLogCapture = $state(false);
|
||||
let forceX11 = $state(false);
|
||||
let gdkScale = $state('');
|
||||
let gdkDpiScale = $state('');
|
||||
@@ -898,6 +904,9 @@
|
||||
forceDmabuf = settings.force_dmabuf;
|
||||
}).catch(() => {});
|
||||
|
||||
// Initialize verbose log capture state (runtime only, not persisted)
|
||||
verboseLogCapture = isVerboseCaptureEnabled();
|
||||
|
||||
// Load graphics settings
|
||||
invoke('get_graphics_settings').then((settings: any) => {
|
||||
forceX11 = settings.force_x11;
|
||||
@@ -2775,6 +2784,21 @@
|
||||
}
|
||||
}
|
||||
|
||||
function handleVerboseLogCaptureChange(enabled: boolean) {
|
||||
if (enabled) {
|
||||
enableVerboseCapture();
|
||||
} else {
|
||||
disableVerboseCapture();
|
||||
}
|
||||
verboseLogCapture = enabled;
|
||||
showToast(
|
||||
enabled
|
||||
? $t('settings.developer.verboseLogEnabled')
|
||||
: $t('settings.developer.verboseLogDisabled'),
|
||||
'info'
|
||||
);
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
if (bytes === 0) return '0 B';
|
||||
const k = 1024;
|
||||
@@ -4289,6 +4313,13 @@
|
||||
</div>
|
||||
<Toggle enabled={forceDmabuf} onchange={handleForceDmabufChange} />
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<span class="setting-label">{$t('settings.developer.verboseLogCapture')}</span>
|
||||
<small class="setting-note">{$t('settings.developer.verboseLogCaptureDesc')}</small>
|
||||
</div>
|
||||
<Toggle enabled={verboseLogCapture} onchange={handleVerboseLogCaptureChange} />
|
||||
</div>
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<span class="setting-label">{$t('settings.developer.viewLogs')}</span>
|
||||
|
||||
@@ -835,7 +835,11 @@
|
||||
"uploadSuccess": "Log-URL in Zwischenablage kopiert",
|
||||
"uploadError": "Fehler beim Hochladen der Logs",
|
||||
"uploading": "Wird hochgeladen...",
|
||||
"bugReportHint": "Fehler melden? Laden Sie beide Tabs hoch und teilen Sie beide URLs — das hilft uns, Probleme schneller zu beheben. Danke!"
|
||||
"bugReportHint": "Fehler melden? Laden Sie beide Tabs hoch und teilen Sie beide URLs — das hilft uns, Probleme schneller zu beheben. Danke!",
|
||||
"verboseLogCapture": "Ausführliche Log-Erfassung",
|
||||
"verboseLogCaptureDesc": "Alle Konsolen-Logs erfassen (log/info), nicht nur Fehler. Verwendet mehr Speicher.",
|
||||
"verboseLogEnabled": "Ausführliche Log-Erfassung aktiviert",
|
||||
"verboseLogDisabled": "Ausführliche Log-Erfassung deaktiviert"
|
||||
},
|
||||
"blacklist": {
|
||||
"title": "Künstler-Blacklist",
|
||||
|
||||
@@ -868,7 +868,11 @@
|
||||
"uploadSuccess": "Log URL copied to clipboard",
|
||||
"uploadError": "Failed to upload logs",
|
||||
"uploading": "Uploading...",
|
||||
"bugReportHint": "Reporting a bug? Upload both tabs and share both URLs — it helps us fix things faster. Thanks!"
|
||||
"bugReportHint": "Reporting a bug? Upload both tabs and share both URLs — it helps us fix things faster. Thanks!",
|
||||
"verboseLogCapture": "Verbose Log Capture",
|
||||
"verboseLogCaptureDesc": "Capture all console logs (log/info), not just errors. Uses more memory.",
|
||||
"verboseLogEnabled": "Verbose log capture enabled",
|
||||
"verboseLogDisabled": "Verbose log capture disabled"
|
||||
},
|
||||
"blacklist": {
|
||||
"title": "Artist Blacklist",
|
||||
|
||||
@@ -868,7 +868,11 @@
|
||||
"uploadSuccess": "URL del log copiada al portapapeles",
|
||||
"uploadError": "Error al subir los logs",
|
||||
"uploading": "Subiendo...",
|
||||
"bugReportHint": "Si vas a reportar un bug, sube ambas pestanas y comparte las dos URLs — nos ayuda a resolver el problema mas rapido. Gracias!"
|
||||
"bugReportHint": "Si vas a reportar un bug, sube ambas pestanas y comparte las dos URLs — nos ayuda a resolver el problema mas rapido. Gracias!",
|
||||
"verboseLogCapture": "Captura de logs detallada",
|
||||
"verboseLogCaptureDesc": "Captura todos los logs de consola (log/info), no solo errores. Usa mas memoria.",
|
||||
"verboseLogEnabled": "Captura de logs detallada activada",
|
||||
"verboseLogDisabled": "Captura de logs detallada desactivada"
|
||||
},
|
||||
"blacklist": {
|
||||
"title": "Lista Negra de Artistas",
|
||||
|
||||
@@ -835,7 +835,11 @@
|
||||
"uploadSuccess": "URL du log copiée dans le presse-papiers",
|
||||
"uploadError": "Échec du téléversement des logs",
|
||||
"uploading": "Téléversement...",
|
||||
"bugReportHint": "Vous signalez un bug ? Téléversez les deux onglets et partagez les deux URLs — cela nous aide a résoudre les problèmes plus vite. Merci !"
|
||||
"bugReportHint": "Vous signalez un bug ? Téléversez les deux onglets et partagez les deux URLs — cela nous aide a résoudre les problèmes plus vite. Merci !",
|
||||
"verboseLogCapture": "Capture de logs detaillee",
|
||||
"verboseLogCaptureDesc": "Capturer tous les logs de console (log/info), pas seulement les erreurs. Utilise plus de memoire.",
|
||||
"verboseLogEnabled": "Capture de logs detaillee activee",
|
||||
"verboseLogDisabled": "Capture de logs detaillee desactivee"
|
||||
},
|
||||
"blacklist": {
|
||||
"title": "Liste noire des artistes",
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
* Wraps console.log/warn/error/info to capture browser-side logs
|
||||
* for the Developer Mode "View Logs" modal. Original console methods
|
||||
* are still called — no breakage.
|
||||
*
|
||||
* Performance optimization:
|
||||
* - error/warn: Always captured (low frequency, high value for bug reports)
|
||||
* - log/info: Only captured in dev builds OR when verbose mode is enabled
|
||||
* (reduces GC/CPU overhead in production)
|
||||
*/
|
||||
|
||||
interface ConsoleEntry {
|
||||
@@ -16,6 +21,10 @@ const MAX_ENTRIES = 2000;
|
||||
let entries: ConsoleEntry[] = [];
|
||||
let initialized = false;
|
||||
|
||||
// Verbose capture mode - when true, captures log/info even in production
|
||||
// Can be enabled via Developer Mode for debugging production issues
|
||||
let verboseCapture = false;
|
||||
|
||||
// Keep references to the real console methods
|
||||
const originalConsole = {
|
||||
log: console.log.bind(console),
|
||||
@@ -48,14 +57,32 @@ function capture(level: ConsoleEntry['level'], args: unknown[]) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we should capture log/info (verbose levels)
|
||||
// In dev builds: always capture everything
|
||||
// In production: only capture if verbose mode is explicitly enabled
|
||||
function shouldCaptureVerbose(): boolean {
|
||||
return import.meta.env.DEV || verboseCapture;
|
||||
}
|
||||
|
||||
export function initConsoleCapture() {
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
||||
// log/info: Only capture in dev OR when verbose mode is enabled
|
||||
console.log = (...args: unknown[]) => {
|
||||
capture('log', args);
|
||||
if (shouldCaptureVerbose()) {
|
||||
capture('log', args);
|
||||
}
|
||||
originalConsole.log(...args);
|
||||
};
|
||||
console.info = (...args: unknown[]) => {
|
||||
if (shouldCaptureVerbose()) {
|
||||
capture('info', args);
|
||||
}
|
||||
originalConsole.info(...args);
|
||||
};
|
||||
|
||||
// warn/error: Always capture (valuable for bug reports)
|
||||
console.warn = (...args: unknown[]) => {
|
||||
capture('warn', args);
|
||||
originalConsole.warn(...args);
|
||||
@@ -64,10 +91,23 @@ export function initConsoleCapture() {
|
||||
capture('error', args);
|
||||
originalConsole.error(...args);
|
||||
};
|
||||
console.info = (...args: unknown[]) => {
|
||||
capture('info', args);
|
||||
originalConsole.info(...args);
|
||||
};
|
||||
}
|
||||
|
||||
/** Enable verbose capture (log/info) in production - for debugging */
|
||||
export function enableVerboseCapture() {
|
||||
verboseCapture = true;
|
||||
originalConsole.info('[ConsoleCapture] Verbose capture enabled');
|
||||
}
|
||||
|
||||
/** Disable verbose capture (log/info) in production */
|
||||
export function disableVerboseCapture() {
|
||||
verboseCapture = false;
|
||||
originalConsole.info('[ConsoleCapture] Verbose capture disabled');
|
||||
}
|
||||
|
||||
/** Check if verbose capture is currently enabled */
|
||||
export function isVerboseCaptureEnabled(): boolean {
|
||||
return verboseCapture;
|
||||
}
|
||||
|
||||
export function getConsoleLogs(): ConsoleEntry[] {
|
||||
|
||||
Reference in new issue
Block a user