2022-10-21 23:17:06 +00:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2022 Vendicated and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-05-05 23:36:00 +00:00
|
|
|
export class Logger {
|
2022-10-30 01:58:11 +00:00
|
|
|
/**
|
|
|
|
* Returns the console format args for a title with the specified background colour and black text
|
|
|
|
* @param color Background colour
|
|
|
|
* @param title Text
|
|
|
|
* @returns Array. Destructure this into {@link Logger}.errorCustomFmt or console.log
|
|
|
|
*
|
|
|
|
* @example logger.errorCustomFmt(...Logger.makeTitleElements("white", "Hello"), "World");
|
|
|
|
*/
|
|
|
|
static makeTitle(color: string, title: string): [string, ...string[]] {
|
|
|
|
return ["%c %c %s ", "", `background: ${color}; color: black; font-weight: bold; border-radius: 5px;`, title];
|
|
|
|
}
|
|
|
|
|
2022-10-30 19:45:18 +00:00
|
|
|
constructor(public name: string, public color: string = "white") { }
|
2022-08-29 18:27:47 +00:00
|
|
|
|
2022-10-30 01:58:11 +00:00
|
|
|
private _log(level: "log" | "error" | "warn" | "info" | "debug", levelColor: string, args: any[], customFmt = "") {
|
2024-06-01 20:51:50 +00:00
|
|
|
if (IS_REPORTER && IS_WEB) {
|
2024-05-29 09:45:44 +00:00
|
|
|
console[level]("[Vencord]", this.name + ":", ...args);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-31 20:08:05 +00:00
|
|
|
console[level](
|
2022-10-30 01:58:11 +00:00
|
|
|
`%c Vencord %c %c ${this.name} ${customFmt}`,
|
2022-08-31 20:08:05 +00:00
|
|
|
`background: ${levelColor}; color: black; font-weight: bold; border-radius: 5px;`,
|
|
|
|
"",
|
|
|
|
`background: ${this.color}; color: black; font-weight: bold; border-radius: 5px;`
|
|
|
|
, ...args
|
|
|
|
);
|
2022-08-29 18:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public log(...args: any[]) {
|
2022-08-31 20:08:05 +00:00
|
|
|
this._log("log", "#a6d189", args);
|
2022-08-29 18:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public info(...args: any[]) {
|
2022-08-31 20:08:05 +00:00
|
|
|
this._log("info", "#a6d189", args);
|
2022-08-29 18:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public error(...args: any[]) {
|
2022-08-31 20:08:05 +00:00
|
|
|
this._log("error", "#e78284", args);
|
2022-08-29 18:27:47 +00:00
|
|
|
}
|
|
|
|
|
2022-10-30 01:58:11 +00:00
|
|
|
public errorCustomFmt(fmt: string, ...args: any[]) {
|
|
|
|
this._log("error", "#e78284", args, fmt);
|
|
|
|
}
|
|
|
|
|
2022-08-29 18:27:47 +00:00
|
|
|
public warn(...args: any[]) {
|
2022-08-31 20:08:05 +00:00
|
|
|
this._log("warn", "#e5c890", args);
|
2022-08-29 18:27:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public debug(...args: any[]) {
|
2022-08-31 20:08:05 +00:00
|
|
|
this._log("debug", "#eebebe", args);
|
2022-08-29 18:27:47 +00:00
|
|
|
}
|
2022-09-16 20:59:34 +00:00
|
|
|
}
|