Changed logger

This commit is contained in:
Thomas FORGIONE 2015-07-07 09:27:03 +02:00
parent c9bfc2dedd
commit 24765a4687
4 changed files with 27 additions and 24 deletions

View File

@ -45,7 +45,7 @@ Log.socket.connection = function(socket) {
log( log(
'[SOK] ' + new Date() + ' ' + '[SOK] ' + new Date() + ' ' +
socket.handshake.address + ' connection', socket.handshake.address + ' connection',
Colors.YELLOW Colors.MAGENTA
); );
}; };
@ -53,7 +53,7 @@ Log.socket.disconnect = function(socket) {
log( log(
'[SOK] ' + new Date() + ' ' + '[SOK] ' + new Date() + ' ' +
socket.handshake.address + ' disconnect', 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; module.exports = Log;

View File

@ -4,12 +4,11 @@
var express = require('express'); var express = require('express');
var fs = require('fs'); var fs = require('fs');
var Log = require('./NodeLog.js');
module.exports = function(parent, options){ module.exports = function(parent){
var verbose = options.verbose;
if (verbose) Log.debug("Loading controllers :");
console.log("Loading controllers :");
fs.readdirSync(__dirname + '/../controllers').forEach(function(name){ fs.readdirSync(__dirname + '/../controllers').forEach(function(name){
@ -28,19 +27,16 @@ module.exports = function(parent, options){
// generate routes based // generate routes based
// on the exported methods // on the exported methods
if (verbose) Log.debug(' ' + name + ':');
console.log('\t' + name + ':');
for (var key in urls) { for (var key in urls) {
app.get(key, obj[urls[key]]); app.get(key, obj[urls[key]]);
if (verbose) Log.debug(' ' + key + ' -> ' + name + '.' + urls[key]);
console.log('\t\t' + key + ' -> ' + name + '.' + urls[key]);
} }
if (verbose) Log.debug();
console.log();
// mount the app // mount the app
parent.use(app); parent.use(app);

View File

@ -4,12 +4,11 @@
var express = require('express'); var express = require('express');
var fs = require('fs'); var fs = require('fs');
var Log = require('./NodeLog.js');
module.exports = function(parent, options){ module.exports = function(parent){
var verbose = options.verbose;
if (verbose) Log.debug("Loading controllers :");
console.log("Loading controllers :");
fs.readdirSync(__dirname + '/../posts').forEach(function(name){ fs.readdirSync(__dirname + '/../posts').forEach(function(name){
@ -28,18 +27,15 @@ module.exports = function(parent, options){
// generate routes based // generate routes based
// on the exported methods // on the exported methods
if (verbose) Log.debug(' ' + name + ':');
console.log('\t' + name + ':');
for (var key in urls) { for (var key in urls) {
app.post(key, obj[urls[key]]); app.post(key, obj[urls[key]]);
if (verbose) Log.debug(' ' + key + ' -> ' + name + '.' + urls[key]);
console.log('\t\t' + key + ' -> ' + name + '.' + urls[key]);
} }
if (verbose) Log.debug();
console.log();
// mount the app // mount the app
parent.use(app); parent.use(app);

View File

@ -59,10 +59,10 @@ app.use(function(req, res, next) {
}); });
// Load controllers // Load controllers
require('./lib/controllers')(app, { verbose: isDev }); require('./lib/controllers')(app);
// Load post to log data from user study // Load post to log data from user study
require('./lib/posts')(app, { verbose: isDev }); require('./lib/posts')(app);
// Static files // Static files
app.use('/static', express.static('static')); app.use('/static', express.static('static'));