You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.8 KiB
65 lines
1.8 KiB
// hopefully separating out styles like this is more readable -- sink
|
|
const styleBase = `@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@700&display=swap'); font-family: 'IBM Plex Mono', monospace;`;
|
|
|
|
const styleBg = `${styleBase} color: #1d1131; background-color: #aa8dd8; font-weight: 600; font-size: 0.9em; padding: 0px 5px 1px 5px; border-radius: 5px;`;
|
|
|
|
const styleTxt = `${styleBase} color: #E2EECE; font-weight: 500; font-size: 0.9em;`;
|
|
|
|
//TODO: make setting to save logs in idb, for debugging and troubleshooting purposes
|
|
function makeLogger(
|
|
print: (...msg: string[]) => void,
|
|
noDemoncord: boolean = false
|
|
) {
|
|
return function (locs: string[], ...messages: string[]): void {
|
|
let message = messages.join("");
|
|
if (locs === undefined) {
|
|
locs = ["Default"];
|
|
makeLogger(console.warn)(
|
|
["Logger"],
|
|
"Requested hierarchy has not been passed to logger function, defaulting to default string"
|
|
);
|
|
}
|
|
if (typeof locs === "string") {
|
|
message = locs;
|
|
locs = ["Default"];
|
|
}
|
|
let rawParts = ["Demoncord", ...locs, message];
|
|
let styleParts: string[] = [];
|
|
let content = "";
|
|
|
|
if (noDemoncord) rawParts.splice(0, 1);
|
|
|
|
for (let i = 0; i < rawParts.length; i++) {
|
|
if (i === rawParts.length - 1) {
|
|
// last item
|
|
content += "%c" + rawParts[i];
|
|
styleParts.push(styleTxt);
|
|
} else {
|
|
content += "%c" + rawParts[i] + "%c ";
|
|
styleParts.push(styleBg, "");
|
|
}
|
|
}
|
|
|
|
print(content, ...styleParts);
|
|
};
|
|
}
|
|
|
|
const log = makeLogger(console.log);
|
|
const warn = makeLogger(console.warn);
|
|
const error = makeLogger(console.error);
|
|
const trace = makeLogger(console.trace);
|
|
const debug = makeLogger((...args) => {
|
|
/*#if _DEBUG
|
|
console.log(...args)
|
|
//#endif */
|
|
});
|
|
|
|
export default {
|
|
log,
|
|
warn,
|
|
error,
|
|
trace,
|
|
debug,
|
|
makeLogger
|
|
};
|