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);
}
});
});
@@ -208,6 +208,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");
@@ -217,7 +237,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 = "";
@@ -438,7 +465,7 @@ For urgent issues, contact us through bitvid’s Nostr support channels.
);
} catch (err) {
log("Error: " + err.message, "error");
console.error(err);
emitUser("error", err);
}
});
});
@@ -142,6 +142,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");
@@ -151,7 +171,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 = "";
@@ -354,7 +381,7 @@ For further questions, reach out through bitvid’s Nostr support channels.
);
} catch (err) {
log("Error: " + err.message, "error");
console.error(err);
emitUser("error", err);
}
});
});
@@ -144,6 +144,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 function for on-page and console output.
function log(msg, type = "info") {
const div = document.createElement("div");
@@ -153,7 +173,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 = "";
@@ -337,7 +364,7 @@ For additional discussions, reach out via bitvid’s Nostr support channels.
);
} catch (err) {
log("Error: " + err.message, "error");
console.error(err);
emitUser("error", err);
}
});
});
@@ -167,6 +167,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 function
function log(msg, type = "info") {
const div = document.createElement("div");
@@ -176,7 +196,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 = "";
@@ -379,7 +406,7 @@ For further discussions, reach out through bitvid’s Nostr support channels.
);
} catch (err) {
log("Error: " + err.message, "error");
console.error(err);
emitUser("error", err);
}
});
});