aboutsummaryrefslogtreecommitdiffstats
path: root/src/debug.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/debug.js')
-rw-r--r--src/debug.js17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/debug.js b/src/debug.js
new file mode 100644
index 0000000..5d7d085
--- /dev/null
+++ b/src/debug.js
@@ -0,0 +1,17 @@
+// A console kept quiet by default. The chatter that helps when something is
+// being chased (the NWC listener's generations, relay health) goes through
+// dlog and shows only once debugging is switched on — from the console with
+// `coinosDebug(true)`, or by opening the app with `?debug=1`. `coinosDebug(false)`
+// turns it off again. Warnings and errors that mean something is wrong are
+// not gated; they stay on console.warn / console.error.
+const KEY = 'coinos-debug';
+export const debugOn = () => { try { return localStorage.getItem(KEY) === '1'; } catch { return false; } };
+export const dlog = (...a) => { if (debugOn()) console.log(...a); };
+if (typeof window !== 'undefined') {
+ window.coinosDebug = (on = true) => {
+ try { localStorage.setItem(KEY, on ? '1' : '0'); } catch {}
+ console.log('coinos debug ' + (on ? 'on' : 'off'));
+ return on;
+ };
+ try { if (new URLSearchParams(location.search).get('debug') === '1') localStorage.setItem(KEY, '1'); } catch {}
+}