mirror of
https://github.com/nimbold/Firelink.git
synced 2026-08-06 01:17:48 +00:00
feat(logging): default to paused state and prevent performance hit via frontend wrapper
- Default LOG_PAUSED to true in backend. - Combine tauri_plugin_log filters to drop backend logs when paused. - Create frontend logger wrapper to intercept and drop logs before IPC when paused. - Sync LogsView state directly with logger wrapper and handle initialization races.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import { info as tauriInfo, warn as tauriWarn, error as tauriError, debug as tauriDebug, trace as tauriTrace, attachLogger as tauriAttachLogger } from '@tauri-apps/plugin-log';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
|
||||
// Default to true to match backend default
|
||||
let isPaused = true;
|
||||
|
||||
let initPromise: Promise<void> | null = null;
|
||||
|
||||
export const initLogger = () => {
|
||||
if (!initPromise) {
|
||||
initPromise = invoke<boolean>('is_log_paused')
|
||||
.then(paused => { isPaused = paused; })
|
||||
.catch(e => console.error("Failed to init logger state", e));
|
||||
}
|
||||
return initPromise;
|
||||
};
|
||||
|
||||
export const setLogPaused = async (pause: boolean) => {
|
||||
isPaused = pause;
|
||||
await invoke('toggle_log_pause', { pause }).catch(console.error);
|
||||
};
|
||||
|
||||
export const getLogPaused = () => isPaused;
|
||||
|
||||
export const info = async (message: string) => {
|
||||
if (!isPaused) return tauriInfo(message);
|
||||
};
|
||||
export const warn = async (message: string) => {
|
||||
if (!isPaused) return tauriWarn(message);
|
||||
};
|
||||
export const error = async (message: string) => {
|
||||
if (!isPaused) return tauriError(message);
|
||||
};
|
||||
export const debug = async (message: string) => {
|
||||
if (!isPaused) return tauriDebug(message);
|
||||
};
|
||||
export const trace = async (message: string) => {
|
||||
if (!isPaused) return tauriTrace(message);
|
||||
};
|
||||
export const attachLogger = tauriAttachLogger;
|
||||
Reference in New Issue
Block a user