Global message type visibility

This commit is contained in:
2024-11-16 13:35:30 -05:00
parent 354e07817d
commit b24f819d85
2 changed files with 17 additions and 5 deletions

20
mod.ts
View File

@@ -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;