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;