From 9461c1692a1bbb3deef474016b05d0feab19e376 Mon Sep 17 00:00:00 2001 From: rejas Date: Mon, 11 May 2020 07:22:40 +0200 Subject: [PATCH 01/14] Add node/browser wrapper around logger --- js/logger.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/js/logger.js b/js/logger.js index 632cf117..7f1e163e 100644 --- a/js/logger.js +++ b/js/logger.js @@ -6,7 +6,15 @@ * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. */ -const Log = (function () { +(function (root, factory) { + if (typeof exports === 'object') { + // Node, CommonJS-like + module.exports = factory(root.config); + } else { + // Browser globals (root is window) + root.Log = factory(root.config); + } +}(this, function (config) { return { info: Function.prototype.bind.call(console.info, console), log: Function.prototype.bind.call(console.log, console), @@ -19,4 +27,4 @@ const Log = (function () { timeEnd: Function.prototype.bind.call(console.timeEnd, console), timeStamp: Function.prototype.bind.call(console.timeStamp, console) }; -})(); +})); From 367233c31832f13dd5b5c64fbd38465bad47b5ef Mon Sep 17 00:00:00 2001 From: rejas Date: Mon, 11 May 2020 07:23:21 +0200 Subject: [PATCH 02/14] Add console-stamp to node-logger --- js/app.js | 3 --- js/logger.js | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/app.js b/js/app.js index fe811a95..d2065d5f 100644 --- a/js/app.js +++ b/js/app.js @@ -13,9 +13,6 @@ var path = require("path"); // Alias modules mentioned in package.js under _moduleAliases. require("module-alias/register"); -// add timestamps in front of log messages -require("console-stamp")(console, "yyyy-mm-dd HH:MM:ss.l"); - // Get version number. global.version = JSON.parse(fs.readFileSync("package.json", "utf8")).version; console.log("Starting MagicMirror: v" + global.version); diff --git a/js/logger.js b/js/logger.js index 7f1e163e..2cbf3b32 100644 --- a/js/logger.js +++ b/js/logger.js @@ -8,6 +8,9 @@ */ (function (root, factory) { if (typeof exports === 'object') { + // add timestamps in front of log messages + require("console-stamp")(console, "yyyy-mm-dd HH:MM:ss.l"); + // Node, CommonJS-like module.exports = factory(root.config); } else { From f2d03a511e0fd192307756b26752aef950372358 Mon Sep 17 00:00:00 2001 From: rejas Date: Mon, 11 May 2020 07:25:42 +0200 Subject: [PATCH 03/14] User logger in node files --- js/app.js | 61 +++++++++++++++++++++++---------------------- js/electron.js | 9 ++++--- js/node_helper.js | 25 ++++++++++--------- js/server.js | 11 ++++---- serveronly/index.js | 8 +++--- 5 files changed, 60 insertions(+), 54 deletions(-) diff --git a/js/app.js b/js/app.js index d2065d5f..3040bd1e 100644 --- a/js/app.js +++ b/js/app.js @@ -10,12 +10,13 @@ var Utils = require(__dirname + "/utils.js"); var defaultModules = require(__dirname + "/../modules/default/defaultmodules.js"); var path = require("path"); +var Log = require("./logger.js"); // Alias modules mentioned in package.js under _moduleAliases. require("module-alias/register"); // Get version number. global.version = JSON.parse(fs.readFileSync("package.json", "utf8")).version; -console.log("Starting MagicMirror: v" + global.version); +Log.log("Starting MagicMirror: v" + global.version); // global absolute root path global.root_path = path.resolve(__dirname + "/../"); @@ -33,10 +34,10 @@ if (process.env.MM_PORT) { // The next part is here to prevent a major exception when there // is no internet connection. This could probable be solved better. process.on("uncaughtException", function (err) { - console.log("Whoops! There was an uncaught exception..."); - console.error(err); - console.log("MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?"); - console.log("If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues"); + Log.log("Whoops! There was an uncaught exception..."); + Log.error(err); + Log.log("MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?"); + Log.log("If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues"); }); /* App - The core app. @@ -50,8 +51,8 @@ var App = function () { * * argument callback function - The callback function. */ - var loadConfig = function (callback) { - console.log("Loading config ..."); + var loadConfig = function(callback) { + Log.log("Loading config ..."); var defaults = require(__dirname + "/defaults.js"); // For this check proposed to TestSuite @@ -69,11 +70,11 @@ var App = function () { callback(config); } catch (e) { if (e.code === "ENOENT") { - console.error(Utils.colors.error("WARNING! Could not find config file. Please create one. Starting with default configuration.")); + Log.error(Utils.colors.error("WARNING! Could not find config file. Please create one. Starting with default configuration.")); } else if (e instanceof ReferenceError || e instanceof SyntaxError) { - console.error(Utils.colors.error("WARNING! Could not validate config file. Starting with default configuration. Please correct syntax errors at or above this line: " + e.stack)); + Log.error(Utils.colors.error("WARNING! Could not validate config file. Starting with default configuration. Please correct syntax errors at or above this line: " + e.stack)); } else { - console.error(Utils.colors.error("WARNING! Could not load config file. Starting with default configuration. Error found: " + e)); + Log.error(Utils.colors.error("WARNING! Could not load config file. Starting with default configuration. Error found: " + e)); } callback(defaults); } @@ -91,7 +92,11 @@ var App = function () { } }); if (usedDeprecated.length > 0) { - console.warn(Utils.colors.warn("WARNING! Your config is using deprecated options: " + usedDeprecated.join(", ") + ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality.")); + Log.warn(Utils.colors.warn( + "WARNING! Your config is using deprecated options: " + + usedDeprecated.join(", ") + + ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality.") + ); } }; @@ -116,7 +121,7 @@ var App = function () { fs.accessSync(helperPath, fs.R_OK); } catch (e) { loadModule = false; - console.log("No helper found for module: " + moduleName + "."); + Log.log("No helper found for module: " + moduleName + "."); } if (loadModule) { @@ -124,11 +129,11 @@ var App = function () { var m = new Module(); if (m.requiresVersion) { - console.log("Check MagicMirror version for node helper '" + moduleName + "' - Minimum version: " + m.requiresVersion + " - Current version: " + global.version); + Log.log("Check MagicMirror version for node helper '" + moduleName + "' - Minimum version: " + m.requiresVersion + " - Current version: " + global.version); if (cmpVersions(global.version, m.requiresVersion) >= 0) { - console.log("Version is ok!"); + Log.log("Version is ok!"); } else { - console.log("Version is incorrect. Skip module: '" + moduleName + "'"); + Log.log("Version is incorrect. Skip module: '" + moduleName + "'"); return; } } @@ -148,8 +153,8 @@ var App = function () { * * argument module string - The name of the module (including subpath). */ - var loadModules = function (modules, callback) { - console.log("Loading module helpers ..."); + var loadModules = function(modules, callback) { + Log.log("Loading module helpers ..."); var loadNextModule = function () { if (modules.length > 0) { @@ -160,7 +165,7 @@ var App = function () { }); } else { // All modules are loaded - console.log("All module helpers loaded."); + Log.log("All module helpers loaded."); callback(); } }; @@ -210,9 +215,9 @@ var App = function () { } } - loadModules(modules, function () { - var server = new Server(config, function (app, io) { - console.log("Server started ..."); + loadModules(modules, function() { + var server = new Server(config, function(app, io) { + Log.log("Server started ..."); for (var h in nodeHelpers) { var nodeHelper = nodeHelpers[h]; @@ -221,7 +226,7 @@ var App = function () { nodeHelper.start(); } - console.log("Sockets connected & modules started ..."); + Log.log("Sockets connected & modules started ..."); if (typeof callback === "function") { callback(config); @@ -252,10 +257,8 @@ var App = function () { * this.stop() is called by app.on("before-quit"... in `electron.js` */ process.on("SIGINT", () => { - console.log("[SIGINT] Received. Shutting down server..."); - setTimeout(() => { - process.exit(0); - }, 3000); // Force quit after 3 seconds + Log.log("[SIGINT] Received. Shutting down server..."); + setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds this.stop(); process.exit(0); }); @@ -263,10 +266,8 @@ var App = function () { /* We also need to listen to SIGTERM signals so we stop everything when we are asked to stop by the OS. */ process.on("SIGTERM", () => { - console.log("[SIGTERM] Received. Shutting down server..."); - setTimeout(() => { - process.exit(0); - }, 3000); // Force quit after 3 seconds + Log.log("[SIGTERM] Received. Shutting down server..."); + setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds this.stop(); process.exit(0); }); diff --git a/js/electron.js b/js/electron.js index 71eed9b8..14e1bf51 100644 --- a/js/electron.js +++ b/js/electron.js @@ -1,7 +1,8 @@ "use strict"; const electron = require("electron"); -const core = require(__dirname + "/app.js"); +const core = require("./app.js"); +const Log = require("./logger.js"); // Config var config = process.env.config ? JSON.parse(process.env.config) : {}; @@ -85,8 +86,8 @@ function createWindow() { // This method will be called when Electron has finished // initialization and is ready to create browser windows. -app.on("ready", function () { - console.log("Launching application."); +app.on("ready", function() { + Log.log("Launching application."); createWindow(); }); @@ -110,7 +111,7 @@ app.on("activate", function () { * core.stop() is called by process.on("SIGINT"... in `app.js` */ app.on("before-quit", (event) => { - console.log("Shutting down server..."); + Log.log("Shutting down server..."); event.preventDefault(); setTimeout(() => { process.exit(0); diff --git a/js/node_helper.js b/js/node_helper.js index 866d34c9..c2e49a78 100644 --- a/js/node_helper.js +++ b/js/node_helper.js @@ -5,20 +5,21 @@ * MIT Licensed. */ const Class = require("./class.js"); +const Log = require("./logger.js"); const express = require("express"); var NodeHelper = Class.extend({ - init: function () { - console.log("Initializing new module helper ..."); + init: function() { + Log.log("Initializing new module helper ..."); }, - loaded: function (callback) { - console.log("Module helper loaded: " + this.name); + loaded: function(callback) { + Log.log("Module helper loaded: " + this.name); callback(); }, - start: function () { - console.log("Starting module helper: " + this.name); + start: function() { + Log.log("Starting module helper: " + this.name); }, /* stop() @@ -27,8 +28,8 @@ var NodeHelper = Class.extend({ * gracefully exit the module. * */ - stop: function () { - console.log("Stopping module helper: " + this.name); + stop: function() { + Log.log("Stopping module helper: " + this.name); }, /* socketNotificationReceived(notification, payload) @@ -37,8 +38,8 @@ var NodeHelper = Class.extend({ * argument notification string - The identifier of the notification. * argument payload mixed - The payload of the notification. */ - socketNotificationReceived: function (notification, payload) { - console.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload); + socketNotificationReceived: function(notification, payload) { + Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload); }, /* setName(name) @@ -92,7 +93,7 @@ var NodeHelper = Class.extend({ var self = this; self.io = io; - console.log("Connecting socket for: " + this.name); + Log.log("Connecting socket for: " + this.name); var namespace = this.name; io.of(namespace).on("connection", function (socket) { // add a catch all event. @@ -107,7 +108,7 @@ var NodeHelper = Class.extend({ // register catch all. socket.on("*", function (notification, payload) { if (notification !== "*") { - //console.log('received message in namespace: ' + namespace); + //Log.log('received message in namespace: ' + namespace); self.socketNotificationReceived(notification, payload); } }); diff --git a/js/server.js b/js/server.js index 7f0c36d0..5116de53 100644 --- a/js/server.js +++ b/js/server.js @@ -4,14 +4,15 @@ * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. */ - var express = require("express"); var app = require("express")(); var path = require("path"); var ipfilter = require("express-ipfilter").IpFilter; var fs = require("fs"); var helmet = require("helmet"); -var Utils = require(__dirname + "/utils.js"); + +var Log = require("./logger.js"); +var Utils = require("./utils.js"); var Server = function (config, callback) { var port = config.port; @@ -31,12 +32,12 @@ var Server = function (config, callback) { } var io = require("socket.io")(server); - console.log("Starting server on port " + port + " ... "); + Log.log("Starting server on port " + port + " ... "); server.listen(port, config.address ? config.address : "localhost"); if (config.ipWhitelist instanceof Array && config.ipWhitelist.length === 0) { - console.info(Utils.colors.warn("You're using a full whitelist configuration to allow for all IPs")); + Log.info(Utils.colors.warn("You're using a full whitelist configuration to allow for all IPs")); } app.use(function (req, res, next) { @@ -44,7 +45,7 @@ var Server = function (config, callback) { if (err === undefined) { return next(); } - console.log(err.message); + Log.log(err.message); res.status(403).send("This device is not allowed to access your mirror.
Please check your config.js or config.js.sample to change this."); }); }); diff --git a/serveronly/index.js b/serveronly/index.js index 44435ec2..b02f5c0c 100644 --- a/serveronly/index.js +++ b/serveronly/index.js @@ -1,6 +1,8 @@ -var app = require("../js/app.js"); -app.start(function (config) { +const app = require("../js/app.js"); +const Log = require("../js/logger.js"); + +app.start(function(config) { var bindAddress = config.address ? config.address : "localhost"; var httpType = config.useHttps ? "https" : "http"; - console.log("\nReady to go! Please point your browser to: " + httpType + "://" + bindAddress + ":" + config.port); + Log.log("\nReady to go! Please point your browser to: " + httpType + "://" + bindAddress + ":" + config.port); }); From d0c6a4ee6d1950c1f120db3745d499a913aedb40 Mon Sep 17 00:00:00 2001 From: Veeck Date: Mon, 11 May 2020 07:46:56 +0200 Subject: [PATCH 04/14] 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; })); From c60446a015909119b3f7c4c1e410dd20627612a7 Mon Sep 17 00:00:00 2001 From: rejas Date: Mon, 11 May 2020 23:12:50 +0200 Subject: [PATCH 05/14] Fix tests --- js/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/app.js b/js/app.js index 3040bd1e..508ac195 100644 --- a/js/app.js +++ b/js/app.js @@ -5,12 +5,12 @@ * MIT Licensed. */ var fs = require("fs"); +var path = require("path"); +var Log = require(__dirname + "/logger.js"); var Server = require(__dirname + "/server.js"); var Utils = require(__dirname + "/utils.js"); var defaultModules = require(__dirname + "/../modules/default/defaultmodules.js"); -var path = require("path"); -var Log = require("./logger.js"); // Alias modules mentioned in package.js under _moduleAliases. require("module-alias/register"); From 0cae954f8018f09043550fab498ae1f57397c3d3 Mon Sep 17 00:00:00 2001 From: rejas Date: Mon, 11 May 2020 23:13:53 +0200 Subject: [PATCH 06/14] Use Log in loader too --- js/loader.js | 62 +++++++++++++++++++++++----------------------------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/js/loader.js b/js/loader.js index 50e7176d..6e20e73d 100644 --- a/js/loader.js +++ b/js/loader.js @@ -171,42 +171,34 @@ var Loader = (function () { var extension = fileName.slice((Math.max(0, fileName.lastIndexOf(".")) || Infinity) + 1); switch (extension.toLowerCase()) { - case "js": - Log.log("Load script: " + fileName); - var script = document.createElement("script"); - script.type = "text/javascript"; - script.src = fileName; - script.onload = function () { - if (typeof callback === "function") { - callback(); - } - }; - script.onerror = function () { - console.error("Error on loading script:", fileName); - if (typeof callback === "function") { - callback(); - } - }; + case "js": + Log.log("Load script: " + fileName); + var script = document.createElement("script"); + script.type = "text/javascript"; + script.src = fileName; + script.onload = function() { + if (typeof callback === "function") {callback();} + }; + script.onerror = function() { + Log.error("Error on loading script:", fileName); + if (typeof callback === "function") {callback();} + }; - document.getElementsByTagName("body")[0].appendChild(script); - break; - case "css": - Log.log("Load stylesheet: " + fileName); - var stylesheet = document.createElement("link"); - stylesheet.rel = "stylesheet"; - stylesheet.type = "text/css"; - stylesheet.href = fileName; - stylesheet.onload = function () { - if (typeof callback === "function") { - callback(); - } - }; - stylesheet.onerror = function () { - console.error("Error on loading stylesheet:", fileName); - if (typeof callback === "function") { - callback(); - } - }; + document.getElementsByTagName("body")[0].appendChild(script); + break; + case "css": + Log.log("Load stylesheet: " + fileName); + var stylesheet = document.createElement("link"); + stylesheet.rel = "stylesheet"; + stylesheet.type = "text/css"; + stylesheet.href = fileName; + stylesheet.onload = function() { + if (typeof callback === "function") {callback();} + }; + stylesheet.onerror = function() { + Log.error("Error on loading stylesheet:", fileName); + if (typeof callback === "function") {callback();} + }; document.getElementsByTagName("head")[0].appendChild(stylesheet); break; From 2334cbd78a4e2516c1ed535bcd8e1a6849087363 Mon Sep 17 00:00:00 2001 From: Veeck Date: Mon, 18 May 2020 09:53:34 +0200 Subject: [PATCH 07/14] User logger in checkconfig script --- js/check_config.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/js/check_config.js b/js/check_config.js index f713657b..ccd786ef 100644 --- a/js/check_config.js +++ b/js/check_config.js @@ -17,6 +17,7 @@ const fs = require("fs"); const rootPath = path.resolve(__dirname + "/../"); const config = require(rootPath + "/.eslintrc.json"); +const Logger = require(rootPath + "/js/logger.js"); const Utils = require(rootPath + "/js/utils.js"); /* getConfigFile() @@ -36,21 +37,20 @@ function checkConfigFile() { const configFileName = getConfigFile(); // Check if file is present if (fs.existsSync(configFileName) === false) { - console.error(Utils.colors.error("File not found: "), configFileName); + Logger.error(Utils.colors.error("File not found: "), configFileName); return; } // check permission try { fs.accessSync(configFileName, fs.F_OK); } catch (e) { - console.log(Utils.colors.error(e)); + Logger.log(Utils.colors.error(e)); return; } // Validate syntax of the configuration file. - // In case the there errors show messages and - // return - console.info(Utils.colors.info("Checking file... "), configFileName); + Logger.info(Utils.colors.info("Checking file... "), configFileName); + // I'm not sure if all ever is utf-8 fs.readFile(configFileName, "utf-8", function (err, data) { if (err) { @@ -58,11 +58,12 @@ function checkConfigFile() { } const messages = linter.verify(data, config); if (messages.length === 0) { - console.log("Your configuration file doesn't contain syntax errors :)"); + Logger.log("Your configuration file doesn't contain syntax errors :)"); return true; } else { - messages.forEach((error) => { - console.log("Line", error.line, "col", error.column, error.message); + // In case the there errors show messages and return + messages.forEach(error => { + Logger.log("Line", error.line, "col", error.column, error.message); }); } }); From 8c319903dd7217e4dcafd81f63066b65cd31a017 Mon Sep 17 00:00:00 2001 From: Veeck Date: Mon, 18 May 2020 10:13:54 +0200 Subject: [PATCH 08/14] Cleanup outcommented logging --- modules/default/calendar/calendar.js | 2 -- modules/default/calendar/calendarfetcher.js | 22 ++++++++------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 3658e1e6..bba7565d 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -282,7 +282,6 @@ Module.register("calendar", { timeWrapper = document.createElement("td"); eventWrapper.appendChild(titleWrapper); - //console.log(event.today); var now = new Date(); // Define second, minute, hour, and day variables var oneSecond = 1000; // 1,000 milliseconds @@ -373,7 +372,6 @@ Module.register("calendar", { } } //timeWrapper.innerHTML += ' - '+ moment(event.startDate,'x').format('lll'); - //console.log(event); timeWrapper.className = "time light " + this.timeClassForUrl(event.url); eventWrapper.appendChild(timeWrapper); } diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 3ab44e47..71284bff 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -58,7 +58,6 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr return; } - // console.log(data); var newEvents = []; // limitFunction doesn't do much limiting, see comment re: the dates array in rrule section below as to why we need to do the filtering ourselves @@ -275,29 +274,28 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr } // end recurring event parsing } else { - // console.log("Single event ..."); // Single event. var fullDayEvent = isFacebookBirthday ? true : isFullDayEvent(event); if (includePastEvents) { + // Past event is too far in the past, so skip. if (endDate < past) { - //console.log("Past event is too far in the past. So skip: " + title); continue; } } else { + // It's not a fullday event, and it is in the past, so skip. if (!fullDayEvent && endDate < new Date()) { - //console.log("It's not a fullday event, and it is in the past. So skip: " + title); continue; } + // It's a fullday event, and it is before today, So skip. if (fullDayEvent && endDate <= today) { - //console.log("It's a fullday event, and it is before today. So skip: " + title); continue; } } + // It exceeds the maximumNumberOfDays limit, so skip. if (startDate > future) { - //console.log("It exceeds the maximumNumberOfDays limit. So skip: " + title); continue; } @@ -305,13 +303,12 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr continue; } - // adjust start date so multiple day events will be displayed as happening today even though they started some days ago already + // Adjust start date so multiple day events will be displayed as happening today even though they started some days ago already if (fullDayEvent && startDate <= today) { startDate = moment(today); } // Every thing is good. Add it to the list. - newEvents.push({ title: title, startDate: startDate.format("x"), @@ -330,8 +327,6 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr return a.startDate - b.startDate; }); - //console.log(newEvents); - events = newEvents.slice(0, maximumEntries); self.broadcastEvents(); @@ -342,8 +337,7 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr /* scheduleTimer() * Schedule the timer for the next update. */ - var scheduleTimer = function () { - //console.log('Schedule update timer.'); + var scheduleTimer = function() { clearTimeout(reloadTimer); reloadTimer = setTimeout(function () { fetchCalendar(); @@ -441,8 +435,8 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr /* broadcastItems() * Broadcast the existing events. */ - this.broadcastEvents = function () { - //console.log('Broadcasting ' + events.length + ' events.'); + this.broadcastEvents = function() { + console.info('Broadcasting ' + events.length + ' events.'); eventsReceivedCallback(self); }; From 13073bc98d39826bd3486266b7b3822c7ce71357 Mon Sep 17 00:00:00 2001 From: Veeck Date: Mon, 25 May 2020 18:57:15 +0200 Subject: [PATCH 09/14] Lint stuff --- js/app.js | 22 ++++---- js/check_config.js | 2 +- js/electron.js | 2 +- js/loader.js | 62 ++++++++++++--------- js/logger.js | 13 ++--- js/node_helper.js | 10 ++-- modules/default/calendar/calendarfetcher.js | 6 +- serveronly/index.js | 2 +- 8 files changed, 63 insertions(+), 56 deletions(-) diff --git a/js/app.js b/js/app.js index 508ac195..600b379a 100644 --- a/js/app.js +++ b/js/app.js @@ -51,7 +51,7 @@ var App = function () { * * argument callback function - The callback function. */ - var loadConfig = function(callback) { + var loadConfig = function (callback) { Log.log("Loading config ..."); var defaults = require(__dirname + "/defaults.js"); @@ -92,11 +92,7 @@ var App = function () { } }); if (usedDeprecated.length > 0) { - Log.warn(Utils.colors.warn( - "WARNING! Your config is using deprecated options: " + - usedDeprecated.join(", ") + - ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality.") - ); + Log.warn(Utils.colors.warn("WARNING! Your config is using deprecated options: " + usedDeprecated.join(", ") + ". Check README and CHANGELOG for more up-to-date ways of getting the same functionality.")); } }; @@ -153,7 +149,7 @@ var App = function () { * * argument module string - The name of the module (including subpath). */ - var loadModules = function(modules, callback) { + var loadModules = function (modules, callback) { Log.log("Loading module helpers ..."); var loadNextModule = function () { @@ -215,8 +211,8 @@ var App = function () { } } - loadModules(modules, function() { - var server = new Server(config, function(app, io) { + loadModules(modules, function () { + var server = new Server(config, function (app, io) { Log.log("Server started ..."); for (var h in nodeHelpers) { @@ -258,7 +254,9 @@ var App = function () { */ process.on("SIGINT", () => { Log.log("[SIGINT] Received. Shutting down server..."); - setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds + setTimeout(() => { + process.exit(0); + }, 3000); // Force quit after 3 seconds this.stop(); process.exit(0); }); @@ -267,7 +265,9 @@ var App = function () { */ process.on("SIGTERM", () => { Log.log("[SIGTERM] Received. Shutting down server..."); - setTimeout(() => { process.exit(0); }, 3000); // Force quit after 3 seconds + setTimeout(() => { + process.exit(0); + }, 3000); // Force quit after 3 seconds this.stop(); process.exit(0); }); diff --git a/js/check_config.js b/js/check_config.js index ccd786ef..da2a4aa5 100644 --- a/js/check_config.js +++ b/js/check_config.js @@ -62,7 +62,7 @@ function checkConfigFile() { return true; } else { // In case the there errors show messages and return - messages.forEach(error => { + messages.forEach((error) => { Logger.log("Line", error.line, "col", error.column, error.message); }); } diff --git a/js/electron.js b/js/electron.js index 14e1bf51..0978cd0d 100644 --- a/js/electron.js +++ b/js/electron.js @@ -86,7 +86,7 @@ function createWindow() { // This method will be called when Electron has finished // initialization and is ready to create browser windows. -app.on("ready", function() { +app.on("ready", function () { Log.log("Launching application."); createWindow(); }); diff --git a/js/loader.js b/js/loader.js index 6e20e73d..bc376bd9 100644 --- a/js/loader.js +++ b/js/loader.js @@ -171,34 +171,42 @@ var Loader = (function () { var extension = fileName.slice((Math.max(0, fileName.lastIndexOf(".")) || Infinity) + 1); switch (extension.toLowerCase()) { - case "js": - Log.log("Load script: " + fileName); - var script = document.createElement("script"); - script.type = "text/javascript"; - script.src = fileName; - script.onload = function() { - if (typeof callback === "function") {callback();} - }; - script.onerror = function() { - Log.error("Error on loading script:", fileName); - if (typeof callback === "function") {callback();} - }; + case "js": + Log.log("Load script: " + fileName); + var script = document.createElement("script"); + script.type = "text/javascript"; + script.src = fileName; + script.onload = function () { + if (typeof callback === "function") { + callback(); + } + }; + script.onerror = function () { + Log.error("Error on loading script:", fileName); + if (typeof callback === "function") { + callback(); + } + }; - document.getElementsByTagName("body")[0].appendChild(script); - break; - case "css": - Log.log("Load stylesheet: " + fileName); - var stylesheet = document.createElement("link"); - stylesheet.rel = "stylesheet"; - stylesheet.type = "text/css"; - stylesheet.href = fileName; - stylesheet.onload = function() { - if (typeof callback === "function") {callback();} - }; - stylesheet.onerror = function() { - Log.error("Error on loading stylesheet:", fileName); - if (typeof callback === "function") {callback();} - }; + document.getElementsByTagName("body")[0].appendChild(script); + break; + case "css": + Log.log("Load stylesheet: " + fileName); + var stylesheet = document.createElement("link"); + stylesheet.rel = "stylesheet"; + stylesheet.type = "text/css"; + stylesheet.href = fileName; + stylesheet.onload = function () { + if (typeof callback === "function") { + callback(); + } + }; + stylesheet.onerror = function () { + Log.error("Error on loading stylesheet:", fileName); + if (typeof callback === "function") { + callback(); + } + }; document.getElementsByTagName("head")[0].appendChild(stylesheet); break; diff --git a/js/logger.js b/js/logger.js index a0f8a038..523b9ce5 100644 --- a/js/logger.js +++ b/js/logger.js @@ -7,7 +7,7 @@ * MIT Licensed. */ (function (root, factory) { - if (typeof exports === 'object') { + if (typeof exports === "object") { // add timestamps in front of log messages require("console-stamp")(console, "yyyy-mm-dd HH:MM:ss.l"); @@ -17,8 +17,7 @@ // Browser globals (root is window) root.Log = factory(root.config); } -}(this, function (config) { - +})(this, function (config) { let logLevel = { info: Function.prototype.bind.call(console.info, console), log: Function.prototype.bind.call(console.log, console), @@ -30,15 +29,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) { + Object.keys(logLevel).forEach(function (key, index) { if (!config.logLevel.includes(key.toLocaleUpperCase())) { - logLevel[key] = function() {}; + logLevel[key] = function () {}; } }); } return logLevel; -})); +}); diff --git a/js/node_helper.js b/js/node_helper.js index c2e49a78..4a31fdee 100644 --- a/js/node_helper.js +++ b/js/node_helper.js @@ -9,16 +9,16 @@ const Log = require("./logger.js"); const express = require("express"); var NodeHelper = Class.extend({ - init: function() { + init: function () { Log.log("Initializing new module helper ..."); }, - loaded: function(callback) { + loaded: function (callback) { Log.log("Module helper loaded: " + this.name); callback(); }, - start: function() { + start: function () { Log.log("Starting module helper: " + this.name); }, @@ -28,7 +28,7 @@ var NodeHelper = Class.extend({ * gracefully exit the module. * */ - stop: function() { + stop: function () { Log.log("Stopping module helper: " + this.name); }, @@ -38,7 +38,7 @@ var NodeHelper = Class.extend({ * argument notification string - The identifier of the notification. * argument payload mixed - The payload of the notification. */ - socketNotificationReceived: function(notification, payload) { + socketNotificationReceived: function (notification, payload) { Log.log(this.name + " received a socket notification: " + notification + " - Payload: " + payload); }, diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 71284bff..d4cc4f4a 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -337,7 +337,7 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr /* scheduleTimer() * Schedule the timer for the next update. */ - var scheduleTimer = function() { + var scheduleTimer = function () { clearTimeout(reloadTimer); reloadTimer = setTimeout(function () { fetchCalendar(); @@ -435,8 +435,8 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr /* broadcastItems() * Broadcast the existing events. */ - this.broadcastEvents = function() { - console.info('Broadcasting ' + events.length + ' events.'); + this.broadcastEvents = function () { + console.info("Broadcasting " + events.length + " events."); eventsReceivedCallback(self); }; diff --git a/serveronly/index.js b/serveronly/index.js index b02f5c0c..9cc7d942 100644 --- a/serveronly/index.js +++ b/serveronly/index.js @@ -1,7 +1,7 @@ const app = require("../js/app.js"); const Log = require("../js/logger.js"); -app.start(function(config) { +app.start(function (config) { var bindAddress = config.address ? config.address : "localhost"; var httpType = config.useHttps ? "https" : "http"; Log.log("\nReady to go! Please point your browser to: " + httpType + "://" + bindAddress + ":" + config.port); From 23c0e015652427ac9deb301efc41546203d95b08 Mon Sep 17 00:00:00 2001 From: rejas Date: Mon, 25 May 2020 23:03:19 +0200 Subject: [PATCH 10/14] Use logger in node_helpers --- modules/default/calendar/node_helper.js | 23 ++++++++--------------- modules/default/newsfeed/node_helper.js | 18 +++++++++--------- 2 files changed, 17 insertions(+), 24 deletions(-) diff --git a/modules/default/calendar/node_helper.js b/modules/default/calendar/node_helper.js index 6af4b72a..6ac5395f 100644 --- a/modules/default/calendar/node_helper.js +++ b/modules/default/calendar/node_helper.js @@ -5,24 +5,21 @@ * MIT Licensed. */ -var NodeHelper = require("node_helper"); -var validUrl = require("valid-url"); -var CalendarFetcher = require("./calendarfetcher.js"); +const NodeHelper = require("node_helper"); +const validUrl = require("valid-url"); +const CalendarFetcher = require("./calendarfetcher.js"); +const Logger = require("../../../js/logger"); module.exports = NodeHelper.create({ // Override start method. start: function () { - var events = []; - + Logger.log("Starting node helper for: " + this.name); this.fetchers = []; - - console.log("Starting node helper for: " + this.name); }, // Override socketNotificationReceived method. socketNotificationReceived: function (notification, payload) { if (notification === "ADD_CALENDAR") { - //console.log('ADD_CALENDAR: '); this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.id); } }, @@ -34,7 +31,6 @@ module.exports = NodeHelper.create({ * attribute url string - URL of the news feed. * attribute reloadInterval number - Reload interval in milliseconds. */ - createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, identifier) { var self = this; @@ -45,13 +41,10 @@ module.exports = NodeHelper.create({ var fetcher; if (typeof self.fetchers[identifier + url] === "undefined") { - console.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval); + Logger.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval); fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents); fetcher.onReceive(function (fetcher) { - //console.log('Broadcast events.'); - //console.log(fetcher.events()); - self.sendSocketNotification("CALENDAR_EVENTS", { id: identifier, url: fetcher.url(), @@ -60,7 +53,7 @@ module.exports = NodeHelper.create({ }); fetcher.onError(function (fetcher, error) { - console.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error); + Logger.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error); self.sendSocketNotification("FETCH_ERROR", { id: identifier, url: fetcher.url(), @@ -70,7 +63,7 @@ module.exports = NodeHelper.create({ self.fetchers[identifier + url] = fetcher; } else { - //console.log('Use existing news fetcher for url: ' + url); + Logger.log("Use existing calendar fetcher for url: " + url); fetcher = self.fetchers[identifier + url]; fetcher.broadcastEvents(); } diff --git a/modules/default/newsfeed/node_helper.js b/modules/default/newsfeed/node_helper.js index f6d6705a..e7748f5f 100644 --- a/modules/default/newsfeed/node_helper.js +++ b/modules/default/newsfeed/node_helper.js @@ -5,22 +5,22 @@ * MIT Licensed. */ -var NodeHelper = require("node_helper"); -var validUrl = require("valid-url"); -var Fetcher = require("./fetcher.js"); +const NodeHelper = require("node_helper"); +const validUrl = require("valid-url"); +const Fetcher = require("./fetcher.js"); +const Logger = require("../../../js/logger"); module.exports = NodeHelper.create({ - // Subclass start method. + // Override start method. start: function () { - console.log("Starting module: " + this.name); + Logger.log("Starting node helper for: " + this.name); this.fetchers = []; }, - // Subclass socketNotificationReceived received. + // Override socketNotificationReceived received. socketNotificationReceived: function (notification, payload) { if (notification === "ADD_FEED") { this.createFetcher(payload.feed, payload.config); - return; } }, @@ -45,7 +45,7 @@ module.exports = NodeHelper.create({ var fetcher; if (typeof self.fetchers[url] === "undefined") { - console.log("Create new news fetcher for url: " + url + " - Interval: " + reloadInterval); + Logger.log("Create new news fetcher for url: " + url + " - Interval: " + reloadInterval); fetcher = new Fetcher(url, reloadInterval, encoding, config.logFeedWarnings); fetcher.onReceive(function (fetcher) { @@ -61,7 +61,7 @@ module.exports = NodeHelper.create({ self.fetchers[url] = fetcher; } else { - console.log("Use existing news fetcher for url: " + url); + Logger.log("Use existing news fetcher for url: " + url); fetcher = self.fetchers[url]; fetcher.setReloadInterval(reloadInterval); fetcher.broadcastItems(); From 2330b166f66cafd47d488f1dff66a094d7c6038a Mon Sep 17 00:00:00 2001 From: rejas Date: Mon, 25 May 2020 23:26:52 +0200 Subject: [PATCH 11/14] Totall forgot we need a changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a7705e9..9c8a78db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ _This release is scheduled to be released on 2020-07-01._ ### Added - Compliments Module - Add Advice API (https://api.adviceslip.com/) Option - +- Added option to config the level of logging - Added prettier for an even cleaner codebase - Hide Sunrise/Sunset in Weather module From 008ac2876b3a9dd00a91de9d90fbbf0c983b1b2d Mon Sep 17 00:00:00 2001 From: rejas Date: Sun, 31 May 2020 22:12:26 +0200 Subject: [PATCH 12/14] More console -> Logger conversions --- js/check_config.js | 12 ++++++------ modules/default/calendar/calendarfetcher.js | 4 ++-- modules/default/calendar/node_helper.js | 10 +++++----- modules/default/newsfeed/fetcher.js | 9 +++++---- modules/default/newsfeed/node_helper.js | 8 ++++---- modules/default/updatenotification/node_helper.js | 15 ++++++++------- 6 files changed, 30 insertions(+), 28 deletions(-) diff --git a/js/check_config.js b/js/check_config.js index da2a4aa5..ab7944c6 100644 --- a/js/check_config.js +++ b/js/check_config.js @@ -17,7 +17,7 @@ const fs = require("fs"); const rootPath = path.resolve(__dirname + "/../"); const config = require(rootPath + "/.eslintrc.json"); -const Logger = require(rootPath + "/js/logger.js"); +const Log = require(rootPath + "/js/logger.js"); const Utils = require(rootPath + "/js/utils.js"); /* getConfigFile() @@ -37,19 +37,19 @@ function checkConfigFile() { const configFileName = getConfigFile(); // Check if file is present if (fs.existsSync(configFileName) === false) { - Logger.error(Utils.colors.error("File not found: "), configFileName); + Log.error(Utils.colors.error("File not found: "), configFileName); return; } // check permission try { fs.accessSync(configFileName, fs.F_OK); } catch (e) { - Logger.log(Utils.colors.error(e)); + Log.log(Utils.colors.error(e)); return; } // Validate syntax of the configuration file. - Logger.info(Utils.colors.info("Checking file... "), configFileName); + Log.info(Utils.colors.info("Checking file... "), configFileName); // I'm not sure if all ever is utf-8 fs.readFile(configFileName, "utf-8", function (err, data) { @@ -58,12 +58,12 @@ function checkConfigFile() { } const messages = linter.verify(data, config); if (messages.length === 0) { - Logger.log("Your configuration file doesn't contain syntax errors :)"); + Log.log("Your configuration file doesn't contain syntax errors :)"); return true; } else { // In case the there errors show messages and return messages.forEach((error) => { - Logger.log("Line", error.line, "col", error.column, error.message); + Log.log("Line", error.line, "col", error.column, error.message); }); } }); diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index d4cc4f4a..6258ed39 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -4,7 +4,7 @@ * By Michael Teeuw https://michaelteeuw.nl * MIT Licensed. */ - +const Log = require("../../../js/logger.js"); const ical = require("./vendor/ical.js"); const moment = require("moment"); @@ -436,7 +436,7 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr * Broadcast the existing events. */ this.broadcastEvents = function () { - console.info("Broadcasting " + events.length + " events."); + Log.info("Broadcasting " + events.length + " events."); eventsReceivedCallback(self); }; diff --git a/modules/default/calendar/node_helper.js b/modules/default/calendar/node_helper.js index 6ac5395f..e731ca6c 100644 --- a/modules/default/calendar/node_helper.js +++ b/modules/default/calendar/node_helper.js @@ -8,12 +8,12 @@ const NodeHelper = require("node_helper"); const validUrl = require("valid-url"); const CalendarFetcher = require("./calendarfetcher.js"); -const Logger = require("../../../js/logger"); +const Log = require("../../../js/logger"); module.exports = NodeHelper.create({ // Override start method. start: function () { - Logger.log("Starting node helper for: " + this.name); + Log.log("Starting node helper for: " + this.name); this.fetchers = []; }, @@ -41,7 +41,7 @@ module.exports = NodeHelper.create({ var fetcher; if (typeof self.fetchers[identifier + url] === "undefined") { - Logger.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval); + Log.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval); fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents); fetcher.onReceive(function (fetcher) { @@ -53,7 +53,7 @@ module.exports = NodeHelper.create({ }); fetcher.onError(function (fetcher, error) { - Logger.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error); + Log.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error); self.sendSocketNotification("FETCH_ERROR", { id: identifier, url: fetcher.url(), @@ -63,7 +63,7 @@ module.exports = NodeHelper.create({ self.fetchers[identifier + url] = fetcher; } else { - Logger.log("Use existing calendar fetcher for url: " + url); + Log.log("Use existing calendar fetcher for url: " + url); fetcher = self.fetchers[identifier + url]; fetcher.broadcastEvents(); } diff --git a/modules/default/newsfeed/fetcher.js b/modules/default/newsfeed/fetcher.js index 3877818b..6140780a 100644 --- a/modules/default/newsfeed/fetcher.js +++ b/modules/default/newsfeed/fetcher.js @@ -5,9 +5,10 @@ * MIT Licensed. */ -var FeedMe = require("feedme"); -var request = require("request"); -var iconv = require("iconv-lite"); +const Log = require("../../../js/logger.js"); +const FeedMe = require("feedme"); +const request = require("request"); +const iconv = require("iconv-lite"); /* Fetcher * Responsible for requesting an update on the set interval and broadcasting the data. @@ -130,7 +131,7 @@ var Fetcher = function (url, reloadInterval, encoding, logFeedWarnings) { //console.log('No items to broadcast yet.'); return; } - //console.log('Broadcasting ' + items.length + ' items.'); + Log.info("Broadcasting " + items.length + " items."); itemsReceivedCallback(self); }; diff --git a/modules/default/newsfeed/node_helper.js b/modules/default/newsfeed/node_helper.js index e7748f5f..4ccef958 100644 --- a/modules/default/newsfeed/node_helper.js +++ b/modules/default/newsfeed/node_helper.js @@ -8,12 +8,12 @@ const NodeHelper = require("node_helper"); const validUrl = require("valid-url"); const Fetcher = require("./fetcher.js"); -const Logger = require("../../../js/logger"); +const Log = require("../../../js/logger"); module.exports = NodeHelper.create({ // Override start method. start: function () { - Logger.log("Starting node helper for: " + this.name); + Log.log("Starting node helper for: " + this.name); this.fetchers = []; }, @@ -45,7 +45,7 @@ module.exports = NodeHelper.create({ var fetcher; if (typeof self.fetchers[url] === "undefined") { - Logger.log("Create new news fetcher for url: " + url + " - Interval: " + reloadInterval); + Log.log("Create new news fetcher for url: " + url + " - Interval: " + reloadInterval); fetcher = new Fetcher(url, reloadInterval, encoding, config.logFeedWarnings); fetcher.onReceive(function (fetcher) { @@ -61,7 +61,7 @@ module.exports = NodeHelper.create({ self.fetchers[url] = fetcher; } else { - Logger.log("Use existing news fetcher for url: " + url); + Log.log("Use existing news fetcher for url: " + url); fetcher = self.fetchers[url]; fetcher.setReloadInterval(reloadInterval); fetcher.broadcastItems(); diff --git a/modules/default/updatenotification/node_helper.js b/modules/default/updatenotification/node_helper.js index 1e47b47e..0c206c5f 100644 --- a/modules/default/updatenotification/node_helper.js +++ b/modules/default/updatenotification/node_helper.js @@ -1,9 +1,10 @@ -var SimpleGit = require("simple-git"); -var simpleGits = []; -var fs = require("fs"); -var path = require("path"); -var defaultModules = require(__dirname + "/../defaultmodules.js"); -var NodeHelper = require("node_helper"); +const SimpleGit = require("simple-git"); +const simpleGits = []; +const fs = require("fs"); +const path = require("path"); +const defaultModules = require(__dirname + "/../defaultmodules.js"); +const Log = require(__dirname + "/../../../js/logger.js"); +const NodeHelper = require("node_helper"); module.exports = NodeHelper.create({ config: {}, @@ -27,7 +28,7 @@ module.exports = NodeHelper.create({ var moduleFolder = path.normalize(__dirname + "/../../" + moduleName); try { - //console.log("checking git for module="+moduleName) + Log.info("Checking git for module: " + moduleName); let stat = fs.statSync(path.join(moduleFolder, ".git")); promises.push(this.resolveRemote(moduleName, moduleFolder)); } catch (err) { From 963b1aa6b1e2fb1293ddaa2955d2010964d36254 Mon Sep 17 00:00:00 2001 From: rejas Date: Mon, 1 Jun 2020 16:40:20 +0200 Subject: [PATCH 13/14] Final cleanups I think --- js/app.js | 6 +++--- js/logger.js | 3 ++- modules/default/calendar/calendarfetcher.js | 2 +- modules/default/newsfeed/fetcher.js | 18 +++++++----------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/js/app.js b/js/app.js index 600b379a..7cf7dd2e 100644 --- a/js/app.js +++ b/js/app.js @@ -34,10 +34,10 @@ if (process.env.MM_PORT) { // The next part is here to prevent a major exception when there // is no internet connection. This could probable be solved better. process.on("uncaughtException", function (err) { - Log.log("Whoops! There was an uncaught exception..."); + Log.error("Whoops! There was an uncaught exception..."); Log.error(err); - Log.log("MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?"); - Log.log("If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues"); + Log.error("MagicMirror will not quit, but it might be a good idea to check why this happened. Maybe no internet connection?"); + Log.error("If you think this really is an issue, please open an issue on GitHub: https://github.com/MichMich/MagicMirror/issues"); }); /* App - The core app. diff --git a/js/logger.js b/js/logger.js index 523b9ce5..157420a7 100644 --- a/js/logger.js +++ b/js/logger.js @@ -1,5 +1,6 @@ /* Magic Mirror - * Logger + * Log + * * This logger is very simple, but needs to be extended. * This system can eventually be used to push the log messages to an external target. * diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index 6258ed39..45338fff 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -436,7 +436,7 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr * Broadcast the existing events. */ this.broadcastEvents = function () { - Log.info("Broadcasting " + events.length + " events."); + Log.info("Calendar-Fetcher: Broadcasting " + events.length + " events."); eventsReceivedCallback(self); }; diff --git a/modules/default/newsfeed/fetcher.js b/modules/default/newsfeed/fetcher.js index 6140780a..da9616dc 100644 --- a/modules/default/newsfeed/fetcher.js +++ b/modules/default/newsfeed/fetcher.js @@ -35,7 +35,6 @@ var Fetcher = function (url, reloadInterval, encoding, logFeedWarnings) { /* fetchNews() * Request the new items. */ - var fetchNews = function () { clearTimeout(reloadTimer); reloadTimer = null; @@ -60,16 +59,15 @@ var Fetcher = function (url, reloadInterval, encoding, logFeedWarnings) { url: url }); } else if (logFeedWarnings) { - console.log("Can't parse feed item:"); - console.log(item); - console.log("Title: " + title); - console.log("Description: " + description); - console.log("Pubdate: " + pubdate); + Log.warn("Can't parse feed item:"); + Log.warn(item); + Log.warn("Title: " + title); + Log.warn("Description: " + description); + Log.warn("Pubdate: " + pubdate); } }); parser.on("end", function () { - //console.log("end parsing - " + url); self.broadcastItems(); scheduleTimer(); }); @@ -94,9 +92,7 @@ var Fetcher = function (url, reloadInterval, encoding, logFeedWarnings) { /* scheduleTimer() * Schedule the timer for the next update. */ - var scheduleTimer = function () { - //console.log('Schedule update timer.'); clearTimeout(reloadTimer); reloadTimer = setTimeout(function () { fetchNews(); @@ -128,10 +124,10 @@ var Fetcher = function (url, reloadInterval, encoding, logFeedWarnings) { */ this.broadcastItems = function () { if (items.length <= 0) { - //console.log('No items to broadcast yet.'); + Log.info("Newsfeed-Fetcher: No items to broadcast yet."); return; } - Log.info("Broadcasting " + items.length + " items."); + Log.info("Newsfeed-Fetcher: Broadcasting " + items.length + " items."); itemsReceivedCallback(self); }; From fd49be1d9bc16812aebdb17ce7bb26e1229118a3 Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Sun, 14 Jun 2020 14:14:30 +0200 Subject: [PATCH 14/14] Remove unreachable code. --- js/check_config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/check_config.js b/js/check_config.js index 5e2aee96..cfd56824 100644 --- a/js/check_config.js +++ b/js/check_config.js @@ -44,7 +44,6 @@ function checkConfigFile() { } catch (e) { Log.log(Utils.colors.error(e)); throw new Error("No permission to access config file!"); - return; } // Validate syntax of the configuration file.