From d0c6a4ee6d1950c1f120db3745d499a913aedb40 Mon Sep 17 00:00:00 2001 From: Veeck Date: Mon, 11 May 2020 07:46:56 +0200 Subject: [PATCH] Make logger configurable --- config/config.js.sample | 1 + js/logger.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/config/config.js.sample b/config/config.js.sample index 40737039..a0164198 100644 --- a/config/config.js.sample +++ b/config/config.js.sample @@ -28,6 +28,7 @@ var config = { httpsCertificate: "", // HTTPS Certificate path, only require when useHttps is true language: "en", + logLevel: ["INFO", "LOG", "WARN", "ERROR"], timeFormat: 24, units: "metric", // serverOnly: true/false/"local" , diff --git a/js/logger.js b/js/logger.js index 2cbf3b32..a0f8a038 100644 --- a/js/logger.js +++ b/js/logger.js @@ -18,7 +18,8 @@ root.Log = factory(root.config); } }(this, function (config) { - return { + + let logLevel = { info: Function.prototype.bind.call(console.info, console), log: Function.prototype.bind.call(console.log, console), error: Function.prototype.bind.call(console.error, console), @@ -29,5 +30,15 @@ time: Function.prototype.bind.call(console.time, console), timeEnd: Function.prototype.bind.call(console.timeEnd, console), timeStamp: Function.prototype.bind.call(console.timeStamp, console) - }; + } + + if (config && config.logLevel) { + Object.keys(logLevel).forEach(function(key,index) { + if (!config.logLevel.includes(key.toLocaleUpperCase())) { + logLevel[key] = function() {}; + } + }); + } + + return logLevel; }));