Permalink
Browse files

Adding ability to have multiple remote clients

  • Loading branch information...
saikat committed Sep 14, 2010
1 parent 8cbfa76 commit 61bde2dbfd3729ea077e04aa7135af10ba897b4c
Showing with 11 additions and 5 deletions.
  1. +11 −5 lib/socket-logger.js
View
@@ -4,7 +4,7 @@ var clientPrototypeSend = null;
function makeLogger() {
var logger = {
stream : process.stdout,
- socketLogger : null,
+ socketLoggers : [],
authToken : null,
logLevel : 0,
failSilently : true,
@@ -18,8 +18,10 @@ function makeLogger() {
return JSON.stringify(obj) + '\n';
});
logger.stream.write(newArr.join(''), 'utf8');
- if (logger.socketLogger && logger.socketLogger.send) {
- logger.socketLogger.send(JSON.stringify(logger.buf));
+ if (logger.socketLoggers.length > 0) {
+ var count = logger.socketLoggers.length;
+ for (var i = 0; i < count; ++i)
+ logger.socketLoggers[i].send(JSON.stringify(logger.buf));
}
logger.buf = [];
}
@@ -52,10 +54,10 @@ function makeLogger() {
return;
var theMessage = ['message'];
if (message === logger.authToken) {
- logger.socketLogger = client;
+ logger.socketLoggers.push(client);
client.send = clientPrototypeSend;
if (logger.socketLoggerSyncer)
- logger.socketLogger.send(logger.socketLoggerSyncer());
+ client.send(logger.socketLoggerSyncer());
return;
}
@@ -74,6 +76,10 @@ function makeLogger() {
}
});
client.on('disconnect', function() {
+ var theSocketLogger = logger.socketLoggers.indexOf(client);
+ if (theSocketLogger != -1)
+ logger.socketLoggers.splice(theSocketLogger, 1);
+
logger.log(['disconnect', client.sessionId]);
});
});

0 comments on commit 61bde2d

Please sign in to comment.