From 2e48f43b726ef43b3be92db417a186c17446e569 Mon Sep 17 00:00:00 2001 From: KGT1 Date: Mon, 18 Jan 2021 07:15:12 +0100 Subject: [PATCH] add logging prefix and colors --- src/index.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index ac1576a..93c95b1 100644 --- a/src/index.js +++ b/src/index.js @@ -10,9 +10,34 @@ try { handleChannelMessage } = require("./messagehandler"); const log = require("loglevel"); + const prefix = require('loglevel-plugin-prefix'); + const chalk = require('chalk'); + const colors = { + TRACE: chalk.magenta, + DEBUG: chalk.cyan, + INFO: chalk.blue, + WARN: chalk.yellow, + ERROR: chalk.red, + }; log.setLevel(CONFIG["log-level"]); + + prefix.reg(log); + log.enableAll(); + + prefix.apply(log, { + format(level, name, timestamp) { + return `${chalk.gray(`[${timestamp}]`)} ${colors[level.toUpperCase()](level)} ${chalk.green(`${name}:`)}`; + }, + }); + + prefix.apply(log.getLogger('critical'), { + format(level, name, timestamp) { + return chalk.red.bold(`[${timestamp}] ${level} ${name}:`); + }, + }); + jellyfinClientManager.init(); // TODO Error Checking as the apiclients is inefficent jellyfinClientManager.getJellyfinClient().authenticateUserByName(CONFIG["jellyfin-username"], CONFIG["jellyfin-password"]).then((response) => { @@ -26,4 +51,4 @@ try { discordClient.login(CONFIG.token); } catch (error) { console.error(error); -} +} \ No newline at end of file