Refactor logging to centralized logger

This commit is contained in:
thePR0M3TH3AN committed 2025-10-15 11:11:14 -04:00
1 parent 08d770162b
commit 37ba57aa37
67 files changed
+1130 -798

No files matched your search

@@ -225,6 +225,26 @@
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const fallbackChannel = {
log: () => {},
info: () => {},
warn: () => {},
error: () => {},
};
const embeddedLogger =
(typeof window !== "undefined" && window.bitvidLogger) || {};
const devChannel = embeddedLogger.dev || fallbackChannel;
const userChannel = embeddedLogger.user || fallbackChannel;
const emitDev = (method, ...args) => {
if (typeof devChannel[method] === "function") {
devChannel[method](...args);
}
};
const emitUser = (method, ...args) => {
if (typeof userChannel[method] === "function") {
userChannel[method](...args);
}
};
// Logging functions for both on-page and console output.
function log(msg, type = "info") {
const div = document.createElement("div");
@@ -234,7 +254,14 @@
if (type === "warn") div.classList.add("warn");
div.textContent = msg;
document.getElementById("status").appendChild(div);
console.log(`[${type.toUpperCase()}] ${msg}`);
const normalized = type.toLowerCase();
if (normalized === "error") {
emitUser("error", `[${type.toUpperCase()}] ${msg}`);
} else if (normalized === "warn") {
emitUser("warn", `[${type.toUpperCase()}] ${msg}`);
} else {
emitDev("info", `[${type.toUpperCase()}] ${msg}`);
}
}
function clear() {
document.getElementById("status").innerHTML = "";
@@ -457,7 +484,7 @@ For further questions, contact us through bitvid’s Nostr support channels.
);
} catch (err) {
log("Error: " + err.message, "error");
console.error(err);
emitUser("error", err);
}
});
});