Permalink
Browse files

Adding logging for responses from the server

  • Loading branch information...
1 parent 91f02ca commit 10036b7108e1eedc03b933cf052c0b729f5a1172 @saikat committed Sep 12, 2010
Showing with 18 additions and 1 deletion.
  1. +18 −1 lib/socket-logger.js
View
@@ -16,15 +16,32 @@ function makeLogger() {
}
},
monitor : function(socket) {
+ var previousBroadcast = socket.broadcast;
+ socket.broadcast = function(message, except) {
+ previousBroadcast.apply(socket, [message, except]);
+ var parsedMsg = JSON.parse(message);
+ logger.log(parsedMsg);
+ };
socket.on('connection', function(client) {
logger.log(['connect', client.sessionId]);
+ var previousSend = client.send;
+ client.send = function(msg) {
+ previousSend.apply(client, [msg]);
+ // Don't log heartbeats
+ if (msg.indexOf("~h~") == -1) {
+ var parsedMsg = JSON.parse(msg);
+ logger.log(["response", client.sessionId, parsedMsg]);
+ }
+ }
client.on('message', function(message) {
try {
if (logger.logLevel === 0)
return;
var theMessage = ['message'];
- if (message === logger.authToken)
+ if (message === logger.authToken) {
logger.socketLogger = client;
+ client.send = Client.prototype.send;
+ }
theMessage.push(client.sessionId);
if (logger.logLevel == 2) {
var parsedMsg = JSON.parse(message);

0 comments on commit 10036b7

Please sign in to comment.