mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-06-06 23:13:58 +02:00
refactor: add proper logging
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(" ")}`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user