Patcher: More useful errors with code diffs (#177)

* Patcher: More useful errors with code diffs

* Nicer log formatting

* PluginCards: ellipsises
This commit is contained in:
Ven 2022-10-30 02:58:11 +01:00 committed by GitHub
parent 739b1e47d4
commit 3af9a14a0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 102 additions and 20 deletions

View file

@ -17,11 +17,23 @@
*/
export default class Logger {
/**
* 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];
}
constructor(public name: string, public color: string) { }
private _log(level: "log" | "error" | "warn" | "info" | "debug", levelColor: string, args: any[]) {
private _log(level: "log" | "error" | "warn" | "info" | "debug", levelColor: string, args: any[], customFmt = "") {
console[level](
`%c Vencord %c %c ${this.name} `,
`%c Vencord %c %c ${this.name} ${customFmt}`,
`background: ${levelColor}; color: black; font-weight: bold; border-radius: 5px;`,
"",
`background: ${this.color}; color: black; font-weight: bold; border-radius: 5px;`
@ -41,6 +53,10 @@ export default class Logger {
this._log("error", "#e78284", args);
}
public errorCustomFmt(fmt: string, ...args: any[]) {
this._log("error", "#e78284", args, fmt);
}
public warn(...args: any[]) {
this._log("warn", "#e5c890", args);
}