From a96f8a89f36ccb980334da2274385373aa3ffb24 Mon Sep 17 00:00:00 2001 From: Ven Date: Mon, 14 Nov 2022 16:22:50 +0100 Subject: MessageLogger: fixes + ignoreSelf & ignoreBots option (#213) --- src/utils/Logger.ts | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/utils/index.ts | 3 ++- src/utils/logger.ts | 67 ---------------------------------------------------- src/utils/updater.ts | 2 +- 4 files changed, 70 insertions(+), 69 deletions(-) create mode 100644 src/utils/Logger.ts delete mode 100644 src/utils/logger.ts (limited to 'src/utils') diff --git a/src/utils/Logger.ts b/src/utils/Logger.ts new file mode 100644 index 0000000..88ebb43 --- /dev/null +++ b/src/utils/Logger.ts @@ -0,0 +1,67 @@ +/* + * 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 . +*/ + +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 = "white") { } + + private _log(level: "log" | "error" | "warn" | "info" | "debug", levelColor: string, args: any[], customFmt = "") { + console[level]( + `%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;` + , ...args + ); + } + + public log(...args: any[]) { + this._log("log", "#a6d189", args); + } + + public info(...args: any[]) { + this._log("info", "#a6d189", args); + } + + public error(...args: any[]) { + 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); + } + + public debug(...args: any[]) { + this._log("debug", "#eebebe", args); + } +} diff --git a/src/utils/index.ts b/src/utils/index.ts index 22504ce..41e1597 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -21,9 +21,10 @@ export * as Constants from "./constants"; export * from "./debounce"; export * as Discord from "./discord"; export { default as IpcEvents } from "./IpcEvents"; -export { default as Logger } from "./logger"; +export { default as Logger } from "./Logger"; export * from "./misc"; export * as Modals from "./modal"; export * from "./onceDefined"; export * from "./proxyLazy"; export * from "./Queue"; + diff --git a/src/utils/logger.ts b/src/utils/logger.ts deleted file mode 100644 index 88ebb43..0000000 --- a/src/utils/logger.ts +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 . -*/ - -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 = "white") { } - - private _log(level: "log" | "error" | "warn" | "info" | "debug", levelColor: string, args: any[], customFmt = "") { - console[level]( - `%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;` - , ...args - ); - } - - public log(...args: any[]) { - this._log("log", "#a6d189", args); - } - - public info(...args: any[]) { - this._log("info", "#a6d189", args); - } - - public error(...args: any[]) { - 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); - } - - public debug(...args: any[]) { - this._log("debug", "#eebebe", args); - } -} diff --git a/src/utils/updater.ts b/src/utils/updater.ts index ea2319f..2ea4953 100644 --- a/src/utils/updater.ts +++ b/src/utils/updater.ts @@ -19,7 +19,7 @@ import gitHash from "~git-hash"; import IpcEvents from "./IpcEvents"; -import Logger from "./logger"; +import Logger from "./Logger"; import { IpcRes } from "./types"; export const UpdateLogger = new Logger("Updater", "white"); -- cgit