From 6fb5fb7b854378bc8bc68f34b567050e424a7c29 Mon Sep 17 00:00:00 2001 From: maksimgrs98 Date: Wed, 4 Dec 2024 00:51:43 +0100 Subject: [PATCH] Delete src/Logger.ts --- src/Logger.ts | 101 -------------------------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 src/Logger.ts diff --git a/src/Logger.ts b/src/Logger.ts deleted file mode 100644 index 34ab4f1..0000000 --- a/src/Logger.ts +++ /dev/null @@ -1,101 +0,0 @@ -import path from "path"; -import { DEBUG } from "./variables"; -import fs from "fs"; - -export type LogOptions = Omit["0"], "type">; - -export class Logger { - public currentLogFile: string; - public tag?: string; - public divider: string = "\n"; - private get pathToLogFolder(): string { - return path.join(__dirname, "../logs"); - } - private get pathToCurrentLog(): string { - return path.join(__dirname, "../logs", this.currentLogFile); - } - - constructor(options?: { tag?: string; divider?: string }) { - this.currentLogFile = this.createNewLogFile(); - if (options === undefined) return; - if (options.tag !== undefined) this.tag = options.tag; - if (options.divider !== undefined) this.divider = options.divider; - } - - private createNewLogFile() { - return ""; - const date = new Date().toISOString().split("T"); - date[1] = date[1].split(".")[0].replaceAll(":", "-"); - const fileName = `${date.join("-")}.log`; - const newLogPath = path.join(this.pathToLogFolder, fileName); - if (!fs.existsSync(newLogPath)) fs.writeFileSync(newLogPath, ""); - const latestLogPath = path.join(this.pathToLogFolder, "./latest.log"); - if (fs.existsSync(latestLogPath)) fs.writeFileSync(latestLogPath, ""); - return fileName; - } - private toString(object: any) { - if (typeof object === "object") - return Object.prototype.toString.call(object); - else if (Array.isArray(object)) return object.join(); - else if (typeof object === "number") return object.toString(); - else if (typeof object === "boolean") return object.toString(); - else if (typeof object === "string") return object; - return "Cannot transfrom object to string"; - } - private appendTextToLog(content: string) { - fs.appendFileSync(this.pathToCurrentLog, content); - fs.appendFileSync(path.join(this.pathToLogFolder, "./latest.log"), content); - } - private writeEntry( - options: { - tag?: string; - type: "log" | "error" | "warn" | "info"; - }, - ...args: any - ) { - return; - const strings: string[] = []; - for (const argument of args) { - const string = this.toString(argument); - strings.push(string); - } - const dateString = new Date().toLocaleString(undefined, { - formatMatcher: "best fit", - dateStyle: "short", - timeStyle: "medium", - }); - let string = `[${dateString}] `; - const tags = [ - ["LTAG", this.tag], - ["TAG", options.tag], - ].filter((i) => i[1] !== undefined); - if (tags.length > 0) { - string += "["; - for (const [tagName, tag] of tags) { - string += `${tagName}: ${tag}`; - } - string += "] "; - } - string += `[${options.type.toUpperCase()}] `; - string += strings.join(this.divider + "\t"); - string += this.divider; - this.appendTextToLog(string); - } - public log(options?: LogOptions, ...args: any) { - if (!DEBUG) console.log(...args); - this.writeEntry({ type: "log", ...options }, ...args); - } - public error(options?: LogOptions, ...args: any) { - if (!DEBUG) console.error(...args); - this.writeEntry({ type: "error", ...options }, ...args); - } - public warn(options?: LogOptions, ...args: any) { - if (!DEBUG) console.warn(...args); - this.writeEntry({ type: "warn", ...options }, ...args); - } - public info(options?: LogOptions, ...args: any) { - if (!DEBUG) console.info(...args); - this.writeEntry({ type: "info", ...options }, ...args); - } -} -export const logger = new Logger({});