aboutsummaryrefslogtreecommitdiff
path: root/core/LogManager.ts
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-07-13 23:34:21 +0200
committerMinteck <contact@minteck.org>2022-07-13 23:34:21 +0200
commit7b5df4ca0a5bd6fcf033ef40563599593b156910 (patch)
tree56cb89f3900adde9da67e7558793a20fb40d7197 /core/LogManager.ts
downloadcooler-pony-7b5df4ca0a5bd6fcf033ef40563599593b156910.tar.gz
cooler-pony-7b5df4ca0a5bd6fcf033ef40563599593b156910.tar.bz2
cooler-pony-7b5df4ca0a5bd6fcf033ef40563599593b156910.zip
Initial commit
Diffstat (limited to 'core/LogManager.ts')
-rw-r--r--core/LogManager.ts84
1 files changed, 84 insertions, 0 deletions
diff --git a/core/LogManager.ts b/core/LogManager.ts
new file mode 100644
index 0000000..916bc67
--- /dev/null
+++ b/core/LogManager.ts
@@ -0,0 +1,84 @@
+import chalk from 'chalk';
+import * as fs from 'fs';
+
+if (!fs.existsSync("logs")) fs.mkdirSync("logs");
+
+export class LogManager {
+ public static logID = new Date().toISOString();
+
+ /**
+ * @return void
+ * @param message - The message to display
+ * @description Shows a warning message
+ */
+ public static warn(message: string): void {
+ let messageParts = message.split(":");
+ let messagePrefix = messageParts[0];
+ messageParts.shift()
+
+ console.log(
+ chalk.gray("[" + new Date().toISOString() + "] ") +
+ chalk.yellow("[warn] ") +
+ (messageParts.length > 0 ? chalk.underline(messagePrefix) + ":" + messageParts.join(":") : messagePrefix)
+ );
+
+ fs.appendFileSync("logs/" + LogManager.logID + ".txt", "\n[" + new Date().toISOString() + "] [warn] " + message);
+ }
+
+ /**
+ * @return void
+ * @param message - The message to display
+ * @description Shows an information message
+ */
+ public static info(message: string): void {
+ let messageParts = message.split(":");
+ let messagePrefix = messageParts[0];
+ messageParts.shift()
+
+ console.log(
+ chalk.gray("[" + new Date().toISOString() + "] ") +
+ chalk.cyan("[info] ") +
+ (messageParts.length > 0 ? chalk.underline(messagePrefix) + ":" + messageParts.join(":") : messagePrefix)
+ );
+
+ fs.appendFileSync("logs/" + LogManager.logID + ".txt", "\n[" + new Date().toISOString() + "] [info] " + message);
+ }
+
+ /**
+ * @return void
+ * @param message - The message to display
+ * @description Shows a debugging message
+ */
+ public static verbose(message: string): void {
+ let messageParts = message.split(":");
+ let messagePrefix = messageParts[0];
+ messageParts.shift()
+
+ console.log(
+ chalk.gray("[" + new Date().toISOString() + "] ") +
+ chalk.green("[verb] ") +
+ (messageParts.length > 0 ? chalk.underline(messagePrefix) + ":" + messageParts.join(":") : messagePrefix)
+ );
+
+ fs.appendFileSync("logs/" + LogManager.logID + ".txt", "\n[" + new Date().toISOString() + "] [verb] " + message);
+ }
+
+ /**
+ * @return void
+ * @param message - The message to display
+ * @description Shows an error message
+ */
+ public static error(message: string): void {
+ let messageParts = message.split(":");
+ let messagePrefix = messageParts[0];
+ messageParts.shift()
+
+ console.log(
+ chalk.gray("[" + new Date().toISOString() + "] ") +
+ chalk.red("[crit] ") +
+ (messageParts.length > 0 ? chalk.underline(messagePrefix) + ":" + messageParts.join(":") : messagePrefix)
+ );
+
+ fs.appendFileSync("logs/" + LogManager.logID + ".txt", "\n[" + new Date().toISOString() + "] [crit] " + message);
+ }
+}