From 15f9a196ff752e57626c4f92fe8458ad8c427673 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Fri, 3 Jan 2020 12:39:49 -0600 Subject: [PATCH] Fixing logging and build version parsing --- bot/bot.js | 2 +- bot/engine.js | 2 +- bot/logging.js | 9 ++++++++- bot/utility.js | 3 ++- entrypoint.sh | 4 ++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/bot/bot.js b/bot/bot.js index 55ab2c0..2c2eb6b 100644 --- a/bot/bot.js +++ b/bot/bot.js @@ -100,7 +100,7 @@ class Bot { } function create(config) { - let buildInfo = utility.getBuildInfo("../build.info") + let buildInfo = utility.getBuildInfo(); logger.info("Running version: %s", buildInfo); return new Bot(config, buildInfo); } diff --git a/bot/engine.js b/bot/engine.js index 2d5a3c9..4fa9f62 100644 --- a/bot/engine.js +++ b/bot/engine.js @@ -24,7 +24,7 @@ class Engine { this.modules.forEach((mod) => { logger.info("Loading module: %s", mod.name); initModule(mod); - console.log("Recognized commands: %s", mod.getRecognizedCommands()) + logger.infog("Recognized commands: %s", mod.getRecognizedCommands()) this.moduleMap.set(mod.command, mod); this.commandMap.set(mod.command, mod); this.commandRadixTree.addWord(mod.command); diff --git a/bot/logging.js b/bot/logging.js index 06e43ac..ddb9f3d 100644 --- a/bot/logging.js +++ b/bot/logging.js @@ -20,10 +20,17 @@ if (process.env.NODE_ENV !== 'production') { winston.format.simple() ) })); +} else { + logger.add(new winston.transports.Console({ + level: 'error', + format: winston.format.combine( + winston.format.simple() + ) + })); } if ('LOG_LEVEL' in process.env) { - logger.info('LOG_LEVEL:', process.env.LOG_LEVEL) + logger.info('LOG_LEVEL: %s', process.env.LOG_LEVEL) logger.level = process.env.LOG_LEVEL } diff --git a/bot/utility.js b/bot/utility.js index 049dfd2..00f962d 100644 --- a/bot/utility.js +++ b/bot/utility.js @@ -26,7 +26,8 @@ function toISODateString(d) { + pad(d.getUTCSeconds()) + 'Z' } -function getBuildInfo(buildInfoPath) { +function getBuildInfo() { + let buildInfoPath = process.env.NODE_PATH + '/build.info'; try { return fs.readFileSync(buildInfoPath, "utf8"); } catch (err) { diff --git a/entrypoint.sh b/entrypoint.sh index 35d1320..4a7f7b1 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -7,9 +7,13 @@ echo "NODE_ENV: ${NODE_ENV}" echo "NODE_PATH: ${NODE_PATH}" echo "LOG_LEVEL: ${LOG_LEVEL}" +echo "Running build version: $(cat build.info)" + case $1 in run) + echo "Baphomet Starting..." node index.js + echo "...Baphomet Shutdown" ;; *) echo "\"$1\" is an unrecognized command"