Skip to content

Commit d38820f

Browse files
Reduce frontend dev logging noise
1 parent 9c3aa85 commit d38820f

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/main.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./utils/tauri-console-filter";
12
import { createRoot } from "react-dom/client";
23
import "./styles.css";
34
import { scan } from "react-scan";

src/utils/frontend-trace.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { invoke } from "@tauri-apps/api/core";
22

33
type TraceLevel = "debug" | "info" | "warn" | "error";
44

5+
const FRONTEND_TRACE_ENABLED = import.meta.env.VITE_FRONTEND_TRACE === "true";
6+
57
function shortPath(value: string) {
68
const normalized = value.replace(/[\\/]+$/, "");
79
const parts = normalized.split(/[\\/]/);
@@ -27,6 +29,8 @@ export function frontendTrace(
2729
message: string,
2830
payload?: Record<string, unknown>,
2931
) {
32+
if (!FRONTEND_TRACE_ENABLED) return;
33+
3034
void invoke("frontend_trace", {
3135
level,
3236
scope,

src/utils/tauri-console-filter.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const FILTERED_TAURI_WARNINGS = [
2+
"IPC custom protocol failed, Tauri will now use the postMessage interface instead",
3+
"[TAURI] Couldn't find callback id",
4+
];
5+
6+
if (import.meta.env.DEV) {
7+
const originalWarn = console.warn.bind(console);
8+
9+
console.warn = (...args: unknown[]) => {
10+
const firstArg = args[0];
11+
if (
12+
typeof firstArg === "string" &&
13+
FILTERED_TAURI_WARNINGS.some((message) => firstArg.startsWith(message))
14+
) {
15+
return;
16+
}
17+
18+
originalWarn(...args);
19+
};
20+
}

0 commit comments

Comments
 (0)