More console -> Logger conversions

This commit is contained in:
rejas 2020-05-31 22:12:26 +02:00
parent 2330b166f6
commit 008ac2876b
6 changed files with 30 additions and 28 deletions

View File

@ -17,7 +17,7 @@ const fs = require("fs");
const rootPath = path.resolve(__dirname + "/../"); const rootPath = path.resolve(__dirname + "/../");
const config = require(rootPath + "/.eslintrc.json"); 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"); const Utils = require(rootPath + "/js/utils.js");
/* getConfigFile() /* getConfigFile()
@ -37,19 +37,19 @@ function checkConfigFile() {
const configFileName = getConfigFile(); const configFileName = getConfigFile();
// Check if file is present // Check if file is present
if (fs.existsSync(configFileName) === false) { if (fs.existsSync(configFileName) === false) {
Logger.error(Utils.colors.error("File not found: "), configFileName); Log.error(Utils.colors.error("File not found: "), configFileName);
return; return;
} }
// check permission // check permission
try { try {
fs.accessSync(configFileName, fs.F_OK); fs.accessSync(configFileName, fs.F_OK);
} catch (e) { } catch (e) {
Logger.log(Utils.colors.error(e)); Log.log(Utils.colors.error(e));
return; return;
} }
// Validate syntax of the configuration file. // 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 // I'm not sure if all ever is utf-8
fs.readFile(configFileName, "utf-8", function (err, data) { fs.readFile(configFileName, "utf-8", function (err, data) {
@ -58,12 +58,12 @@ function checkConfigFile() {
} }
const messages = linter.verify(data, config); const messages = linter.verify(data, config);
if (messages.length === 0) { 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; return true;
} else { } else {
// In case the there errors show messages and return // 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); Log.log("Line", error.line, "col", error.column, error.message);
}); });
} }
}); });

View File

@ -4,7 +4,7 @@
* By Michael Teeuw https://michaelteeuw.nl * By Michael Teeuw https://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
const Log = require("../../../js/logger.js");
const ical = require("./vendor/ical.js"); const ical = require("./vendor/ical.js");
const moment = require("moment"); const moment = require("moment");
@ -436,7 +436,7 @@ var CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntr
* Broadcast the existing events. * Broadcast the existing events.
*/ */
this.broadcastEvents = function () { this.broadcastEvents = function () {
console.info("Broadcasting " + events.length + " events."); Log.info("Broadcasting " + events.length + " events.");
eventsReceivedCallback(self); eventsReceivedCallback(self);
}; };

View File

@ -8,12 +8,12 @@
const NodeHelper = require("node_helper"); const NodeHelper = require("node_helper");
const validUrl = require("valid-url"); const validUrl = require("valid-url");
const CalendarFetcher = require("./calendarfetcher.js"); const CalendarFetcher = require("./calendarfetcher.js");
const Logger = require("../../../js/logger"); const Log = require("../../../js/logger");
module.exports = NodeHelper.create({ module.exports = NodeHelper.create({
// Override start method. // Override start method.
start: function () { start: function () {
Logger.log("Starting node helper for: " + this.name); Log.log("Starting node helper for: " + this.name);
this.fetchers = []; this.fetchers = [];
}, },
@ -41,7 +41,7 @@ module.exports = NodeHelper.create({
var fetcher; var fetcher;
if (typeof self.fetchers[identifier + url] === "undefined") { 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 = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents);
fetcher.onReceive(function (fetcher) { fetcher.onReceive(function (fetcher) {
@ -53,7 +53,7 @@ module.exports = NodeHelper.create({
}); });
fetcher.onError(function (fetcher, error) { 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", { self.sendSocketNotification("FETCH_ERROR", {
id: identifier, id: identifier,
url: fetcher.url(), url: fetcher.url(),
@ -63,7 +63,7 @@ module.exports = NodeHelper.create({
self.fetchers[identifier + url] = fetcher; self.fetchers[identifier + url] = fetcher;
} else { } 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 = self.fetchers[identifier + url];
fetcher.broadcastEvents(); fetcher.broadcastEvents();
} }

View File

@ -5,9 +5,10 @@
* MIT Licensed. * MIT Licensed.
*/ */
var FeedMe = require("feedme"); const Log = require("../../../js/logger.js");
var request = require("request"); const FeedMe = require("feedme");
var iconv = require("iconv-lite"); const request = require("request");
const iconv = require("iconv-lite");
/* Fetcher /* Fetcher
* Responsible for requesting an update on the set interval and broadcasting the data. * 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.'); //console.log('No items to broadcast yet.');
return; return;
} }
//console.log('Broadcasting ' + items.length + ' items.'); Log.info("Broadcasting " + items.length + " items.");
itemsReceivedCallback(self); itemsReceivedCallback(self);
}; };

View File

@ -8,12 +8,12 @@
const NodeHelper = require("node_helper"); const NodeHelper = require("node_helper");
const validUrl = require("valid-url"); const validUrl = require("valid-url");
const Fetcher = require("./fetcher.js"); const Fetcher = require("./fetcher.js");
const Logger = require("../../../js/logger"); const Log = require("../../../js/logger");
module.exports = NodeHelper.create({ module.exports = NodeHelper.create({
// Override start method. // Override start method.
start: function () { start: function () {
Logger.log("Starting node helper for: " + this.name); Log.log("Starting node helper for: " + this.name);
this.fetchers = []; this.fetchers = [];
}, },
@ -45,7 +45,7 @@ module.exports = NodeHelper.create({
var fetcher; var fetcher;
if (typeof self.fetchers[url] === "undefined") { 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 = new Fetcher(url, reloadInterval, encoding, config.logFeedWarnings);
fetcher.onReceive(function (fetcher) { fetcher.onReceive(function (fetcher) {
@ -61,7 +61,7 @@ module.exports = NodeHelper.create({
self.fetchers[url] = fetcher; self.fetchers[url] = fetcher;
} else { } else {
Logger.log("Use existing news fetcher for url: " + url); Log.log("Use existing news fetcher for url: " + url);
fetcher = self.fetchers[url]; fetcher = self.fetchers[url];
fetcher.setReloadInterval(reloadInterval); fetcher.setReloadInterval(reloadInterval);
fetcher.broadcastItems(); fetcher.broadcastItems();

View File

@ -1,9 +1,10 @@
var SimpleGit = require("simple-git"); const SimpleGit = require("simple-git");
var simpleGits = []; const simpleGits = [];
var fs = require("fs"); const fs = require("fs");
var path = require("path"); const path = require("path");
var defaultModules = require(__dirname + "/../defaultmodules.js"); const defaultModules = require(__dirname + "/../defaultmodules.js");
var NodeHelper = require("node_helper"); const Log = require(__dirname + "/../../../js/logger.js");
const NodeHelper = require("node_helper");
module.exports = NodeHelper.create({ module.exports = NodeHelper.create({
config: {}, config: {},
@ -27,7 +28,7 @@ module.exports = NodeHelper.create({
var moduleFolder = path.normalize(__dirname + "/../../" + moduleName); var moduleFolder = path.normalize(__dirname + "/../../" + moduleName);
try { try {
//console.log("checking git for module="+moduleName) Log.info("Checking git for module: " + moduleName);
let stat = fs.statSync(path.join(moduleFolder, ".git")); let stat = fs.statSync(path.join(moduleFolder, ".git"));
promises.push(this.resolveRemote(moduleName, moduleFolder)); promises.push(this.resolveRemote(moduleName, moduleFolder));
} catch (err) { } catch (err) {