mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-07-25 05:40:50 +02:00
refactor: add proper logging
This commit is contained in:
@@ -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