Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Feature/better logging #45

Merged
merged 4 commits into from

2 participants

@stelcheck

Reopening from #40

stelcheck added some commits
@stelcheck stelcheck * Allow for configurable logging option (basic callback function)
* TODO: create level logging
0a9ef4f
@stelcheck stelcheck * Bugfix: Ftp methods were note prototype methods
* Uncaught exception now prints stacktrace instead of just the error message
f894d24
@stelcheck stelcheck * Bugfix: ftp source was not calling back on error
* Refactored ftp source
* ftp source will not consider 6xx as errors (which is more compliant with return code specifications)
7115c13
@stelcheck stelcheck Merge branch 'master' into feature/better-logging
Conflicts:
	server.js
fa1057e
@obazoud obazoud merged commit 30d7111 into statusdashboard:master
@obazoud
Owner

Thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 24, 2013
  1. @stelcheck

    * Allow for configurable logging option (basic callback function)

    stelcheck authored
    * TODO: create level logging
  2. @stelcheck

    * Bugfix: Ftp methods were note prototype methods

    stelcheck authored
    * Uncaught exception now prints stacktrace instead of just the error message
  3. @stelcheck

    * Bugfix: ftp source was not calling back on error

    stelcheck authored
    * Refactored ftp source
    * ftp source will not consider 6xx as errors (which is more compliant with return code specifications)
  4. @stelcheck

    Merge branch 'master' into feature/better-logging

    stelcheck authored
    Conflicts:
    	server.js
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 20 deletions.
  1. +8 −5 api.js
  2. +9 −6 plugins/irc/irc_plugin.js
  3. +11 −9 server.js
View
13 api.js
@@ -1,11 +1,12 @@
var util = require('util'),
fs = require('fs'),
- logger = require('util'),
_ = require('underscore')._,
humanized_time_span = require(__dirname + '/lib/humanized_time_span.js'),
EventEmitter = require('events').EventEmitter,
controller = new EventEmitter();
+var log;
+
/**
Set this module as an express.js controller
*/
@@ -21,6 +22,8 @@ module.exports.setup = function (settings) {
module.exports.configure(settings);
+ log = settings.logger ? settings.logger : require('util').log;
+
/**
Load available plugins
*/
@@ -30,11 +33,11 @@ module.exports.setup = function (settings) {
if (fs.statSync(__dirname + '/plugins/' + directory).isDirectory() && fs.statSync(__dirname + '/plugins/' + directory + '/' + directory + '_plugin.js').isFile()) {
return require(__dirname + '/plugins/' + directory + '/' + directory + '_plugin.js').create(controller, settings);
} else {
- logger.log("Excluding plugin: " + directory);
+ log("Excluding plugin: " + directory);
}
});
} else {
- logger.log("Error when creating plugin: " + err);
+ log("Error when creating plugin: " + err);
}
});
@@ -58,7 +61,7 @@ module.exports.configure = function (s) {
};
module.exports.addService = function (serviceCfg) {
- logger.log('Adding new service: ' + serviceCfg.name);
+ log('Adding new service: ' + serviceCfg.name);
module.exports.removeService(serviceCfg.name);
settings.services.push(serviceCfg);
};
@@ -85,7 +88,7 @@ status.services = [];
module.exports.checkAllServices = function() {
status.lastupdate = new Date().toUTCString();
- logger.log('Refreshing status board...');
+ log('Refreshing status board...');
/**
Update the service status object, check the service
View
15 plugins/irc/irc_plugin.js
@@ -1,9 +1,12 @@
var _ = require('underscore')._,
- logger = require('util');
+ log;
exports.create = function(api, settings) {
+
+ log = settings.logger ? settings.logger : require('util').log;
+
if (settings.plugins && settings.plugins.irc && settings.plugins.irc.enable) {
- logger.log('Creating the plugin: ' + __filename);
+ log('Creating the plugin: ' + __filename);
var irc = require('irc');
var channels = settings.plugins.irc.options.channels;
@@ -61,11 +64,11 @@ exports.create = function(api, settings) {
});
bot.on('join', function(channel, who) {
- logger.log(who + ' has joined ' + channel);
+ log(who + ' has joined ' + channel);
if (who == settings.plugins.irc.nick) {
// TODO : Let's do it for each channel of the list...
- logger.log('You are now connected to channel ' + channel + ' and ready to send messages');
+ log('You are now connected to channel ' + channel + ' and ready to send messages');
connected = true;
_.each(cache, function(message){
bot.say(channels, message);
@@ -76,7 +79,7 @@ exports.create = function(api, settings) {
// Add a private message listener to interact with the IRC bot
bot.addListener('pm', function(nick, message) {
- logger.log('Got private message from ' + nick + ': ' + message);
+ log('Got private message from ' + nick + ': ' + message);
var callme = commands[trim(message)];
if (typeof callme !== 'undefined') {
bot.say(nick, callme.call(null, api));
@@ -88,7 +91,7 @@ exports.create = function(api, settings) {
// Send the message or cache it
var pushMessage = function(message) {
- logger.log('Pushing message ' + message);
+ log('Pushing message ' + message);
if (connected) {
bot.say(channels, message);
} else {
View
20 server.js
@@ -1,14 +1,16 @@
var path = require('path'),
- util = require('util'),
url = require('url'),
_ = require('underscore')._;
+var log;
+
exports.dashboard = function(settings, cb) {
var rootPath = path.dirname(module.filename),
api = require('./api'),
express = require('express'),
app = express.createServer();
+ log = settings.logger ? settings.logger : require('util').log;
/**
Express app definition
@@ -18,7 +20,7 @@ exports.dashboard = function(settings, cb) {
app.configure(function () {
var staticPath = path.join(rootPath, 'public');
- util.log("Express server static directory: " + staticPath);
+ log("Express server static directory: " + staticPath);
app.use(express['static'].call(null, staticPath));
app.use(express.favicon(path.join(staticPath, 'favicon.ico')));
@@ -29,7 +31,7 @@ exports.dashboard = function(settings, cb) {
app.listen(settings.port, settings.hostname);
- util.log('Server running at http://' + settings.hostname + ':' + settings.port);
+ log('Server running at http://' + settings.hostname + ':' + settings.port);
/**
Routes are connected to the api, and an extra route is added for self-health checking
@@ -66,7 +68,7 @@ exports.dashboard = function(settings, cb) {
io.sockets.on('connection', function(socket) {
count++;
- util.log('New client connected! (' + count + ')');
+ log('New client connected! (' + count + ')');
socket.emit('title', settings.title);
socket.emit('status', api.getStatus());
@@ -75,7 +77,7 @@ exports.dashboard = function(settings, cb) {
socket.on('disconnect', function() {
count--;
- util.log('Client disconnect! (' + count + ')');
+ log('Client disconnect! (' + count + ')');
socket.broadcast.emit('count', count);
});
});
@@ -94,18 +96,18 @@ exports.dashboard = function(settings, cb) {
api.on("routeContribution", function(route) {
app.get(route.path, route.binding);
- util.log("Add GET route contribution: " + route.path);
+ log("Add GET route contribution: " + route.path);
});
api.on("postRouteContribution", function(route) {
app.post(route.path, route.binding);
- util.log("Add POST route contribution: " + route.path);
+ log("Add POST route contribution: " + route.path);
});
api.on("staticContribution", function(plugin) {
var docRoot = __dirname + '/plugins/' + plugin + '/public';
app.use("/api/" + plugin, express['static'].call(null, docRoot));
- util.log("Add static contribution: " + plugin + ", " + docRoot);
+ log("Add static contribution: " + plugin + ", " + docRoot);
});
api.on("refresh", function(status) {
@@ -116,6 +118,6 @@ exports.dashboard = function(settings, cb) {
// We make the API available for external control
this.api = api;
- util.log('Server started.');
+ log('Server started.');
if (cb) cb();
};
Something went wrong with that request. Please try again.