From e8af26913edcdd8c27aff9a2d30d349e9b1bf3a9 Mon Sep 17 00:00:00 2001 From: Thomas FORGIONE Date: Fri, 3 Jul 2015 11:57:45 +0200 Subject: [PATCH] Colors in log (if dev) --- server.js | 4 +++- socket.js | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/server.js b/server.js index 83763d6..553f049 100644 --- a/server.js +++ b/server.js @@ -38,9 +38,11 @@ app.use(function(req, res, next) { // Log connection console.log( + (isDev ? '\033[32m' : '') + '[REQ] ' + new Date() + ' ' + (req.headers['x-forwarded-for'] || req.connection.remoteAddress) + - ' : ' + req.url + ' : ' + req.url + + (isDev ? '\033[0m' : '') ); res.locals.title = "3DUI"; diff --git a/socket.js b/socket.js index 8a351d7..a408fb6 100644 --- a/socket.js +++ b/socket.js @@ -1,13 +1,23 @@ var fs = require('fs'); var geo = require('./lib/geo.min.js'); +var isDev = require('express')().get('env') === 'development'; + module.exports = function(io) { io.on('connection', function(socket) { - console.log('[SOK] ' + new Date() + ' ' + socket.handshake.address + ' connection'); + console.log( + (isDev ? '\033[33m' : '') + + '[SOK] ' + new Date() + ' ' + socket.handshake.address + ' connection' + + (isDev ? '\033[0m' : '') + ); socket.on('disconnect', function() { - console.log('[SOK] ' + new Date() + ' ' + socket.handshake.address + ' disconnect'); + console.log( + (isDev ? '\033[34m' : '') + + '[SOK] ' + new Date() + ' ' + socket.handshake.address + ' disconnect' + + (isDev ? '\033[0m' : '') + ); }); var streamer = new geo.MeshStreamer();