From 09b01f5ccfbcfab31357f86b0e0292a5faa39824 Mon Sep 17 00:00:00 2001 From: baldo Date: Tue, 24 May 2016 19:14:09 +0200 Subject: [PATCH] Nicer logging + Monitoring progress --- config.json.example | 9 +++++-- server/config.js | 6 +++-- server/jobs/scheduler.js | 11 +++++---- server/logger.js | 36 +++++++++++++++++----------- server/services/monitoringService.js | 7 ++++++ 5 files changed, 47 insertions(+), 22 deletions(-) diff --git a/config.json.example b/config.json.example index 38cdf48..162af75 100644 --- a/config.json.example +++ b/config.json.example @@ -7,7 +7,9 @@ "peersPath": "/tmp/peers", "logging": { - "directory": "/tmp/logs" + "directory": "/tmp/logs", + "debug": false, + "logRequests": false }, "email": { @@ -25,7 +27,7 @@ }, "map": { - "nodesJsonUrl": "https://map.hamburg.freifunk.net/nodes.json" + "nodesJsonUrl": "http://musterstadt.freifunk.net/nodes.json" } }, "client": { @@ -37,6 +39,9 @@ "map": { "mapUrl": "http://map.hamburg.freifunk.net" }, + "monitoring": { + "enabled": false + }, "coordsSelector": { "lat": 53.565278, "lng": 10.001389, diff --git a/server/config.js b/server/config.js index 4ca96b0..4a70f84 100644 --- a/server/config.js +++ b/server/config.js @@ -12,7 +12,9 @@ var defaultConfig = { peersPath: '/tmp/peers', logging: { - directory: '/tmp/logs' + directory: '/tmp/logs', + debug: false, + logRequests: false }, email: { @@ -44,7 +46,7 @@ var defaultConfig = { mapUrl: 'http://map.musterstadt.freifunk.net' }, monitoring: { - enabled: true + enabled: false }, coordsSelector: { showInfo: false, diff --git a/server/jobs/scheduler.js b/server/jobs/scheduler.js index d8a87ab..b3e7613 100644 --- a/server/jobs/scheduler.js +++ b/server/jobs/scheduler.js @@ -8,7 +8,7 @@ _.each(jobFiles, function (jobFile) { require(jobFile); }); -angular.module('ffffng').factory('Scheduler', function ($injector, Logger) { +angular.module('ffffng').factory('Scheduler', function ($injector, Logger, config) { var cron = require('node-cron'); function schedule(expr, jobName) { @@ -29,9 +29,12 @@ angular.module('ffffng').factory('Scheduler', function ($injector, Logger) { try { schedule('0 */1 * * * *', 'MailQueueJob'); - // schedule('0 */5 * * * *', 'NodeInformationRetrievalJob'); - schedule('*/10 * * * * *', 'NodeInformationRetrievalJob'); - // schedule('0 */1 * * * *', 'NodeInformationCleanupJob'); + + if (config.client.monitoring.enabled) { + // schedule('0 */5 * * * *', 'NodeInformationRetrievalJob'); + schedule('*/10 * * * * *', 'NodeInformationRetrievalJob'); + // schedule('0 */1 * * * *', 'NodeInformationCleanupJob'); + } } catch (error) { Logger.tag('jobs').error('Error during scheduling of background jobs:', error); diff --git a/server/logger.js b/server/logger.js index 2967399..d751ce4 100644 --- a/server/logger.js +++ b/server/logger.js @@ -2,26 +2,34 @@ var config = require('./config'); + +// Hack to allow proper logging of Error. +Object.defineProperty(Error.prototype, 'message', { + configurable: true, + enumerable: true +}); +Object.defineProperty(Error.prototype, 'stack', { + configurable: true, + enumerable: true +}); + + var scribe = require('scribe-js')({ - app: 'ffffng', - id: process.pid, - rootPath: config.server.logging.directory, - - module: { - 'router/Viewer': { - username: false, - password: false - } - } }); -process.console.addLogger('debug', 'grey', { - logInConsole: false -}); +if (config.server.logging.debug) { + process.console.addLogger('debug', 'grey', { + logInConsole: false + }); +} else { + process.console.debug = function () {}; +} angular.module('ffffng').factory('Logger', function (app) { - app.use(scribe.express.logger()); + if (config.server.logging.logRequests) { + app.use(scribe.express.logger()); + } app.use('/internal/logs', scribe.webPanel()); return process.console; diff --git a/server/services/monitoringService.js b/server/services/monitoringService.js index c5ec448..f54fd78 100644 --- a/server/services/monitoringService.js +++ b/server/services/monitoringService.js @@ -241,6 +241,13 @@ angular.module('ffffng') return callback(err); } + if (response.statusCode !== 200) { + return callback(new Error( + 'Could not download nodes.json from ' + url + ': ' + + response.statusCode + ' - ' + response.statusMessage + )); + } + parseNodesJson(body, function (err, data) { if (err) { return callback(err);