frontend: rework logging system

This commit is contained in:
hippoz 2022-05-05 20:52:35 +03:00
parent 243036f29e
commit 144877e682
No known key found for this signature in database
GPG key ID: 7C52899193467641
5 changed files with 20 additions and 28 deletions

View file

@ -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,

View file

@ -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
);
}
};
}

View file

@ -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
};

View file

@ -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;

View file

@ -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]") {