forked from Demon/demoncord
make logger less bad
parent
9d51c98be8
commit
2c4505bcc2
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"tabWidth": 4,
|
||||||
|
"singleQuote": false,
|
||||||
|
"semi": true,
|
||||||
|
"bracketSpacing": true,
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": "*.js",
|
||||||
|
"options": {
|
||||||
|
"parser": "babel-flow"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
@ -1,19 +1,63 @@
|
|||||||
//@flow
|
//@flow
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
`;
|
||||||
|
|
||||||
|
type LogFuncs = "log" | "error" | "warn" | "trace" | "group";
|
||||||
|
type LoggerFunction = (message: string, locs: string[]) => void;
|
||||||
|
|
||||||
//TODO: make setting to save logs in idb, for debugging and troubleshooting purposes
|
//TODO: make setting to save logs in idb, for debugging and troubleshooting purposes
|
||||||
//bg: #aa8dd8
|
function getLogger(type: LogFuncs): LoggerFunction {
|
||||||
//fg: #553986
|
return function (message, locs) {
|
||||||
function log(message: string, type: string, ...locs: string[]): void {
|
let rawParts = ["Demoncord", ...locs, message];
|
||||||
let string = "%cDemoncord%c "
|
let styleParts = [];
|
||||||
let style = []
|
let content = "";
|
||||||
for (let i = 0; i < locs.length; i++) {
|
|
||||||
const loc = locs[i]
|
for (let i = 0; i < rawParts.length; i++) {
|
||||||
style.push("@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@700&display=swap'); font-family: 'IBM Plex Mono', monospace; font-weight: 600; background-color: #aa8dd8; color: #1d1131; border-radius: 5px; padding: 0px 5px 1px 5px; font-size: 0.9em;", "")
|
if (i === rawParts.length - 1) {
|
||||||
string += `%c${loc}%c `
|
// last item
|
||||||
}
|
content += "%c" + rawParts[i];
|
||||||
style.push("@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@700&display=swap'); font-family: 'IBM Plex Mono', monospace; font-weight: 600; background-color: #aa8dd8; color: #1d1131; border-radius: 5px; padding: 0px 5px 1px 5px; font-size: 0.9em;", "")
|
styleParts.push(styleTxt);
|
||||||
string += `%c${message}`
|
} else {
|
||||||
style.push("@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@700&display=swap'); font-family: 'IBM Plex Mono', monospace; font-weight: 500; font-size: 0.9em; color: #E2EECE;")
|
content += "%c" + rawParts[i] + "%c ";
|
||||||
console[type](string, ...style)
|
styleParts.push(styleBg, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console[type](content, ...styleParts);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default log;
|
const log: LoggerFunction = getLogger("log");
|
||||||
|
const warn: LoggerFunction = getLogger("warn");
|
||||||
|
const error: LoggerFunction = getLogger("error");
|
||||||
|
const trace: LoggerFunction = getLogger("trace");
|
||||||
|
const group: LoggerFunction = getLogger("group");
|
||||||
|
|
||||||
|
export default {
|
||||||
|
log,
|
||||||
|
warn,
|
||||||
|
error,
|
||||||
|
trace,
|
||||||
|
group
|
||||||
|
};
|
||||||
|
Loading…
Reference in new issue