diff --git a/lib/NodeLog.js b/lib/NodeLog.js index 09ea208..6d7175f 100644 --- a/lib/NodeLog.js +++ b/lib/NodeLog.js @@ -45,7 +45,7 @@ Log.socket.connection = function(socket) { log( '[SOK] ' + new Date() + ' ' + socket.handshake.address + ' connection', - Colors.YELLOW + Colors.MAGENTA ); }; @@ -53,7 +53,7 @@ Log.socket.disconnect = function(socket) { log( '[SOK] ' + new Date() + ' ' + socket.handshake.address + ' disconnect', - Colors.YELLOW + Colors.MAGENTA ); }; @@ -64,4 +64,15 @@ Log.dberror = function(error) { ); }; +if (isDev) { + Log.debug = function(info) { + log( + '[DBG] ' + (info !== undefined ? info : ''), + Colors.YELLOW + ); + }; +} else { + Log.debug = function(){}; +} + module.exports = Log; diff --git a/lib/controllers.js b/lib/controllers.js index cb0bdf5..e1a9b4f 100644 --- a/lib/controllers.js +++ b/lib/controllers.js @@ -4,12 +4,11 @@ var express = require('express'); var fs = require('fs'); +var Log = require('./NodeLog.js'); -module.exports = function(parent, options){ - var verbose = options.verbose; +module.exports = function(parent){ - if (verbose) - console.log("Loading controllers :"); + Log.debug("Loading controllers :"); fs.readdirSync(__dirname + '/../controllers').forEach(function(name){ @@ -28,19 +27,16 @@ module.exports = function(parent, options){ // generate routes based // on the exported methods - if (verbose) - console.log('\t' + name + ':'); + Log.debug(' ' + name + ':'); for (var key in urls) { app.get(key, obj[urls[key]]); - if (verbose) - console.log('\t\t' + key + ' -> ' + name + '.' + urls[key]); + Log.debug(' ' + key + ' -> ' + name + '.' + urls[key]); } - if (verbose) - console.log(); + Log.debug(); // mount the app parent.use(app); diff --git a/lib/posts.js b/lib/posts.js index c29c304..3e58109 100644 --- a/lib/posts.js +++ b/lib/posts.js @@ -4,12 +4,11 @@ var express = require('express'); var fs = require('fs'); +var Log = require('./NodeLog.js'); -module.exports = function(parent, options){ - var verbose = options.verbose; +module.exports = function(parent){ - if (verbose) - console.log("Loading controllers :"); + Log.debug("Loading controllers :"); fs.readdirSync(__dirname + '/../posts').forEach(function(name){ @@ -28,18 +27,15 @@ module.exports = function(parent, options){ // generate routes based // on the exported methods - if (verbose) - console.log('\t' + name + ':'); + Log.debug(' ' + name + ':'); for (var key in urls) { app.post(key, obj[urls[key]]); - if (verbose) - console.log('\t\t' + key + ' -> ' + name + '.' + urls[key]); + Log.debug(' ' + key + ' -> ' + name + '.' + urls[key]); } - if (verbose) - console.log(); + Log.debug(); // mount the app parent.use(app); diff --git a/server.js b/server.js index f425e5b..47822a5 100644 --- a/server.js +++ b/server.js @@ -59,10 +59,10 @@ app.use(function(req, res, next) { }); // Load controllers -require('./lib/controllers')(app, { verbose: isDev }); +require('./lib/controllers')(app); // Load post to log data from user study -require('./lib/posts')(app, { verbose: isDev }); +require('./lib/posts')(app); // Static files app.use('/static', express.static('static'));