diff --git a/frontend/src/gateway.js b/frontend/src/gateway.js index 8f94d6a..3be957f 100644 --- a/frontend/src/gateway.js +++ b/frontend/src/gateway.js @@ -1,4 +1,4 @@ -import logging from "./logging"; +import logger from "./logging"; import { getItem } from "./storage"; export const GatewayErrors = { @@ -35,7 +35,7 @@ export const GatewayEventType = { BadAuth: -3, } -const log = logging.logger("Gateway", true); +const log = logger("Gateway"); export default { ws: null, diff --git a/frontend/src/logging.js b/frontend/src/logging.js index a6305f3..14f0546 100644 --- a/frontend/src/logging.js +++ b/frontend/src/logging.js @@ -1,21 +1,13 @@ -export default { - sinks: new Map(), - logger(sink, enabled=false) { - this.sinks.set(sink, enabled); - return (...args) => { - if (this.sinks.get(sink)) { - console.log( - `%c[${sink}]`, - "color: #8f3f71; font-weight: bold;", - ...args - ); - } - }; - }, - enableSink(sink) { - this.sinks.set(sink, true); - }, - disableSink(sink) { - this.sinks.set(sink, false); - } -}; +import { getItem } from "./storage"; + +export default function logger(sink) { + return (...args) => { + if (getItem(`loggingSink:${sink}`)) { + console.log( + `%c[${sink}]`, + "color: #8f3f71; font-weight: bold;", + ...args + ); + } + }; +} diff --git a/frontend/src/main.js b/frontend/src/main.js index ca0c24e..99d22b9 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -1,12 +1,10 @@ import Main from './components/Main.svelte'; import gateway from './gateway'; import { getItem, init } from './storage'; -import logging from "./logging"; import { authWithToken, useAuthHandlers } from './auth'; import { initResponsiveHandlers } from './responsive'; window.__waffle = { - logging, gateway }; diff --git a/frontend/src/storage.js b/frontend/src/storage.js index 83b7a36..04245b2 100644 --- a/frontend/src/storage.js +++ b/frontend/src/storage.js @@ -2,7 +2,9 @@ const defaults = { apiBase: `${window.location.origin}/api/v1`, gatewayBase: `${location.protocol === "https:" ? "wss" : "ws"}://${location.host}/gateway`, doAnimations: true, - token: "" + token: "", + "loggingSink:Gateway": false, + "loggingSink:Store": false }; const store = new Map(Object.entries(defaults)); const persistentProvider = localStorage; diff --git a/frontend/src/stores.js b/frontend/src/stores.js index c6a0d3e..f1967c2 100644 --- a/frontend/src/stores.js +++ b/frontend/src/stores.js @@ -1,9 +1,9 @@ import gateway, { GatewayEventType } from "./gateway"; -import logging from "./logging"; +import logger from "./logging"; import request from "./request"; import { apiRoute } from "./storage"; -const storeLog = logging.logger("Store", true); +const storeLog = logger("Store"); class Store { constructor(value=null, name="[unnamed]") {