Global message type visibility
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
"chalk": "npm:chalk@^5.3.0"
|
"chalk": "npm:chalk@^5.3.0"
|
||||||
},
|
},
|
||||||
"exports": "./mod.ts",
|
"exports": "./mod.ts",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"name": "@proxnet/undead-logging",
|
"name": "@proxnet/undead-logging",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
}
|
}
|
||||||
|
|||||||
20
mod.ts
20
mod.ts
@@ -44,6 +44,7 @@ class Logging {
|
|||||||
i(...msgs: string[]) {this.info(...msgs);}
|
i(...msgs: string[]) {this.info(...msgs);}
|
||||||
/** Logging Function */
|
/** Logging Function */
|
||||||
info(...msgs: string[]) {
|
info(...msgs: string[]) {
|
||||||
|
if (!MessageTypeVisibility.Info) return;
|
||||||
if (this.visible !== true) return;
|
if (this.visible !== true) return;
|
||||||
console.log(chalk.gray(`${new Date().toISOString()} `) + chalk.bgWhite.black(`${this.source} [INFO]`) + chalk.whiteBright(' ' + msgs.join(' ')));
|
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);}
|
w(...msgs: string[]) {this.warn(...msgs);}
|
||||||
/** Logging Function */
|
/** Logging Function */
|
||||||
warn(...msgs: string[]) {
|
warn(...msgs: string[]) {
|
||||||
|
if (!MessageTypeVisibility.Warn) return;
|
||||||
if (this.visible !== true) return;
|
if (this.visible !== true) return;
|
||||||
console.warn(chalk.gray(`${new Date().toISOString()} `) + chalk.bgYellow.black(`${this.source} [WARN]`) + chalk.yellowBright(' ' + msgs.join(' ')));
|
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);}
|
e(...msgs: string[]) {this.error(...msgs);}
|
||||||
/** Logging Function */
|
/** Logging Function */
|
||||||
error(...msgs: string[]) {
|
error(...msgs: string[]) {
|
||||||
|
if (!MessageTypeVisibility.Error) return;
|
||||||
if (this.visible !== true) return;
|
if (this.visible !== true) return;
|
||||||
console.error(chalk.gray(`${new Date().toISOString()} `) + chalk.bgRed.black(`${this.source} [ERROR]`) + chalk.redBright(' ' + msgs.join(' ')));
|
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);}
|
d(...msgs: string[]) {this.debug(...msgs);}
|
||||||
/** Logging Function */
|
/** Logging Function */
|
||||||
debug(...msgs: string[]) {
|
debug(...msgs: string[]) {
|
||||||
|
if (!MessageTypeVisibility.Debug) return;
|
||||||
if (this.visible !== true) return;
|
if (this.visible !== true) return;
|
||||||
console.debug(chalk.gray(`${new Date().toISOString()} `) + chalk.bgGreen.black(`${this.source} [DEBUG]`) + chalk.greenBright(' ' + msgs.join(' ')));
|
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);}
|
n(...msgs: string[]) {this.network(...msgs);}
|
||||||
/** Logging Function */
|
/** Logging Function */
|
||||||
network(...msgs: string[]) {
|
network(...msgs: string[]) {
|
||||||
|
if (!MessageTypeVisibility.Network) return;
|
||||||
if (this.visible !== true) return;
|
if (this.visible !== true) return;
|
||||||
console.log(chalk.gray(`${new Date().toISOString()} `) + chalk.bgCyan.black(`${this.source} [NETWORK]`) + chalk.cyanBright(' ' + msgs.join(' ')));
|
console.log(chalk.gray(`${new Date().toISOString()} `) + chalk.bgCyan.black(`${this.source} [NETWORK]`) + chalk.cyanBright(' ' + msgs.join(' ')));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Useful for conditional logging with the `log` function */
|
||||||
* Useful for conditional logging in the `log` function.
|
|
||||||
*/
|
|
||||||
enum MessageType {
|
enum MessageType {
|
||||||
Info,
|
Info,
|
||||||
Warn,
|
Warn,
|
||||||
@@ -93,5 +96,14 @@ enum MessageType {
|
|||||||
Network
|
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;
|
export default Logging;
|
||||||
Reference in New Issue
Block a user