From cc8b106157f4f7df6cdb7108ed7ad912d595473b Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 24 Nov 2021 13:10:41 +0100 Subject: [PATCH] Added logger-setup-module --- src/helper/logger.js | 11 +++++++++++ src/main.js | 8 +++----- 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 src/helper/logger.js diff --git a/src/helper/logger.js b/src/helper/logger.js new file mode 100644 index 0000000..6e61ab0 --- /dev/null +++ b/src/helper/logger.js @@ -0,0 +1,11 @@ +const log4js = require("log4js"); + + +function setup(category = "unknown"){ + const logger = log4js.getLogger(category); + logger.level = process.env.LOGLEVEL ?? "INFO"; + return logger; +} + +// Specify exports +module.exports = setup; \ No newline at end of file diff --git a/src/main.js b/src/main.js index 586503c..c1569b7 100644 --- a/src/main.js +++ b/src/main.js @@ -1,15 +1,13 @@ -const log4js = require("log4js"); +const logger = require("./helper/logger.js")("main"); + const { requireEnvVars } = require("./helper/env.js"); const { exit } = require("process"); -/// Setup logger -const logger = log4js.getLogger("main"); -logger.level = process.env.LOGLEVEL ?? "INFO"; - /// Setup ENVs const env = process.env; // Defaults { + env.LOGLEVEL ??= "INFO"; env.WIFI_INTERFACE ??= "wlan0"; env.WIFI_CHANNEL ??= [1,6,11]; env.WIFI_CHANNEL_TIME ??= 1;