From 188d455a27036f725b54831d1ffd592d08f31d20 Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:33:09 -0400 Subject: [PATCH] Route beacon logging through shared logger --- torrent/app.js | 21 +++++++++++---------- torrent/js/utils/logger.js | 2 ++ torrent/src/beacon-vendor.js | 7 +++++-- 3 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 torrent/js/utils/logger.js diff --git a/torrent/app.js b/torrent/app.js index a7fd30e5..447c1519 100644 --- a/torrent/app.js +++ b/torrent/app.js @@ -1,3 +1,4 @@ +import { devLogger, userLogger } from "../js/utils/logger.js"; import { createBeaconToast } from "./ui/toastService.js"; import { createTorrentTable } from "./ui/torrentTable.js"; @@ -93,7 +94,7 @@ function prepareTorrentFiles(torrent) { torrent.fileName = `${name}.torrent`; } } catch (error) { - console.warn("[beacon] Failed to create torrent blob URL", error); + devLogger.warn("[beacon] Failed to create torrent blob URL", error); } } } @@ -414,7 +415,7 @@ export function createBeaconApp({ file.getBlob((err, blob) => { if (err || !blob) { - console.error("[beacon] Failed to get blob for file", file?.name, err); + userLogger.error("[beacon] Failed to get blob for file", file?.name, err); toast.error("Failed to prepare file for download."); return; } @@ -448,7 +449,7 @@ export function createBeaconApp({ toast.success("Magnet URI copied to clipboard!"); }) .catch((error) => { - console.error("[beacon] Clipboard error", error); + userLogger.error("[beacon] Clipboard error", error); toast.error("Failed to copy magnet URI"); }); return; @@ -465,7 +466,7 @@ export function createBeaconApp({ documentRef.body.removeChild(textarea); toast.success("Magnet URI copied (fallback)!"); } catch (error) { - console.error("[beacon] Clipboard fallback error", error); + userLogger.error("[beacon] Clipboard fallback error", error); toast.error("Failed to copy magnet URI"); } } @@ -477,7 +478,7 @@ export function createBeaconApp({ torrent.destroy((error) => { if (error) { - console.error("[beacon] Failed to destroy torrent", error); + userLogger.error("[beacon] Failed to destroy torrent", error); toast.error("Failed to remove torrent"); } @@ -489,10 +490,10 @@ export function createBeaconApp({ } function mount() { - console.log(`[beacon] Starting beacon runtime v${VERSION}`); + devLogger.info(`[beacon] Starting beacon runtime v${VERSION}`); if (!toast) { - console.warn("[beacon] Toast service unavailable"); + devLogger.warn("[beacon] Toast service unavailable"); } if (!WebTorrentClass.WEBRTC_SUPPORT) { @@ -569,7 +570,7 @@ export function createBeaconApp({ } const errorHandler = (error) => { - console.error("[beacon] Torrent client error", error); + userLogger.error("[beacon] Torrent client error", error); toast?.error(error?.message || String(error)); setProcessing(false); }; @@ -616,7 +617,7 @@ export function createBeaconApp({ try { task(); } catch (error) { - console.warn("[beacon] Cleanup task failed", error); + devLogger.warn("[beacon] Cleanup task failed", error); } }); cleanupTasks.length = 0; @@ -626,7 +627,7 @@ export function createBeaconApp({ try { client.destroy(); } catch (error) { - console.warn("[beacon] Failed to destroy client", error); + devLogger.warn("[beacon] Failed to destroy client", error); } } diff --git a/torrent/js/utils/logger.js b/torrent/js/utils/logger.js new file mode 100644 index 00000000..a86d500d --- /dev/null +++ b/torrent/js/utils/logger.js @@ -0,0 +1,2 @@ +export { default } from "../../../js/utils/logger.js"; +export * from "../../../js/utils/logger.js"; diff --git a/torrent/src/beacon-vendor.js b/torrent/src/beacon-vendor.js index 51e31443..1ff88bee 100644 --- a/torrent/src/beacon-vendor.js +++ b/torrent/src/beacon-vendor.js @@ -1,3 +1,4 @@ +import { devLogger, userLogger } from "../js/utils/logger.js"; import { createBeaconApp } from "../app.js"; function resolveGlobalScope() { @@ -22,6 +23,7 @@ let appInstance = null; function mountBeaconApp() { if (appInstance) { + devLogger.info("[beacon] Reusing existing beacon app instance"); return appInstance; } @@ -30,6 +32,7 @@ function mountBeaconApp() { } const WebTorrentCtor = resolveWebTorrent(); + devLogger.info("[beacon] Creating beacon app instance"); appInstance = createBeaconApp({ documentRef: document, WebTorrentCtor }); appInstance.mount(); return appInstance; @@ -41,14 +44,14 @@ if (typeof document !== "undefined") { try { mountBeaconApp(); } catch (error) { - console.error("[beacon] Failed to mount app", error); + userLogger.error("[beacon] Failed to mount app", error); } }); } else { try { mountBeaconApp(); } catch (error) { - console.error("[beacon] Failed to mount app", error); + userLogger.error("[beacon] Failed to mount app", error); } } }