From 3af9a14a0e78be88c5a048b79187c32796c06a7c Mon Sep 17 00:00:00 2001 From: Ven Date: Sun, 30 Oct 2022 02:58:11 +0100 Subject: Patcher: More useful errors with code diffs (#177) * Patcher: More useful errors with code diffs * Nicer log formatting * PluginCards: ellipsises --- src/utils/logger.ts | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/utils') diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 309f4db..24cd2c8 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -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); } -- cgit