refactor: add proper logging

This commit is contained in:
zhom
2025-11-26 20:21:17 +04:00
parent bab9301c31
commit 0b63ad6556
28 changed files with 1119 additions and 631 deletions
+6
View File
@@ -2,10 +2,12 @@
import { Geist, Geist_Mono } from "next/font/google";
import "@/styles/globals.css";
import "flag-icons/css/flag-icons.min.css";
import { useEffect } from "react";
import { CustomThemeProvider } from "@/components/theme-provider";
import { Toaster } from "@/components/ui/sonner";
import { TooltipProvider } from "@/components/ui/tooltip";
import { WindowDragArea } from "@/components/window-drag-area";
import { setupLogging } from "@/lib/logger";
const geistSans = Geist({
variable: "--font-geist-sans",
@@ -22,6 +24,10 @@ export default function RootLayout({
}: Readonly<{
children: React.ReactNode;
}>) {
useEffect(() => {
void setupLogging();
}, []);
return (
<html lang="en" suppressHydrationWarning>
<body
+42
View File
@@ -0,0 +1,42 @@
import {
attachConsole,
debug,
error,
info,
trace,
warn,
} from "@tauri-apps/plugin-log";
let consoleAttached = false;
export async function setupLogging() {
if (consoleAttached) {
return;
}
try {
await attachConsole();
consoleAttached = true;
} catch (err) {
// If attachConsole fails, log to regular console as fallback
console.error("Failed to attach console to logging plugin:", err);
}
}
export const logger = {
error: (message: string, ...args: unknown[]) => {
error(`${message} ${args.map((arg) => JSON.stringify(arg)).join(" ")}`);
},
warn: (message: string, ...args: unknown[]) => {
warn(`${message} ${args.map((arg) => JSON.stringify(arg)).join(" ")}`);
},
info: (message: string, ...args: unknown[]) => {
info(`${message} ${args.map((arg) => JSON.stringify(arg)).join(" ")}`);
},
debug: (message: string, ...args: unknown[]) => {
debug(`${message} ${args.map((arg) => JSON.stringify(arg)).join(" ")}`);
},
log: (message: string, ...args: unknown[]) => {
trace(`${message} ${args.map((arg) => JSON.stringify(arg)).join(" ")}`);
},
};