diff --git a/deno.json b/deno.json index 1c7a30c..a2feefe 100644 --- a/deno.json +++ b/deno.json @@ -4,7 +4,7 @@ "chalk": "npm:chalk@^5.3.0" }, "exports": "./mod.ts", - "version": "1.1.0", + "version": "1.2.0", "name": "@proxnet/undead-logging", "license": "MIT" } diff --git a/mod.ts b/mod.ts index a129cb8..e072f98 100644 --- a/mod.ts +++ b/mod.ts @@ -44,6 +44,7 @@ class Logging { i(...msgs: string[]) {this.info(...msgs);} /** Logging Function */ info(...msgs: string[]) { + if (!MessageTypeVisibility.Info) return; if (this.visible !== true) return; console.log(chalk.gray(`${new Date().toISOString()} `) + chalk.bgWhite.black(`${this.source} [INFO]`) + chalk.whiteBright(' ' + msgs.join(' '))); } @@ -52,6 +53,7 @@ class Logging { w(...msgs: string[]) {this.warn(...msgs);} /** Logging Function */ warn(...msgs: string[]) { + if (!MessageTypeVisibility.Warn) return; if (this.visible !== true) return; console.warn(chalk.gray(`${new Date().toISOString()} `) + chalk.bgYellow.black(`${this.source} [WARN]`) + chalk.yellowBright(' ' + msgs.join(' '))); } @@ -60,6 +62,7 @@ class Logging { e(...msgs: string[]) {this.error(...msgs);} /** Logging Function */ error(...msgs: string[]) { + if (!MessageTypeVisibility.Error) return; if (this.visible !== true) return; console.error(chalk.gray(`${new Date().toISOString()} `) + chalk.bgRed.black(`${this.source} [ERROR]`) + chalk.redBright(' ' + msgs.join(' '))); } @@ -68,6 +71,7 @@ class Logging { d(...msgs: string[]) {this.debug(...msgs);} /** Logging Function */ debug(...msgs: string[]) { + if (!MessageTypeVisibility.Debug) return; if (this.visible !== true) return; console.debug(chalk.gray(`${new Date().toISOString()} `) + chalk.bgGreen.black(`${this.source} [DEBUG]`) + chalk.greenBright(' ' + msgs.join(' '))); } @@ -76,15 +80,14 @@ class Logging { n(...msgs: string[]) {this.network(...msgs);} /** Logging Function */ network(...msgs: string[]) { + if (!MessageTypeVisibility.Network) return; if (this.visible !== true) return; console.log(chalk.gray(`${new Date().toISOString()} `) + chalk.bgCyan.black(`${this.source} [NETWORK]`) + chalk.cyanBright(' ' + msgs.join(' '))); } } -/** - * Useful for conditional logging in the `log` function. - */ +/** Useful for conditional logging with the `log` function */ enum MessageType { Info, Warn, @@ -93,5 +96,14 @@ enum MessageType { Network } -export { MessageType }; +/** Enable/disable logging of certain message types across all logging sources */ +const MessageTypeVisibility = { + Info: true, + Warn: true, + Error: true, + Debug: true, + Network: true +} + +export { MessageType, MessageTypeVisibility }; export default Logging; \ No newline at end of file