Browse files

Adding timestamps

  • Loading branch information...
1 parent 55a8bf3 commit 9fc02912d089ed8ec6026a7f6867ee3dd7fdece7 @saikat committed Sep 2, 2010
Showing with 17 additions and 13 deletions.
  1. +8 −5 example/dashboard/AppController.j
  2. +9 −8 lib/socket-logger.js
View
13 example/dashboard/AppController.j
@@ -91,11 +91,14 @@
- (void)socket:(SCSocket)aSocket didReceiveMessage:(CPString)aMessage
{
- var theLetter = aMessage.body.c;
- var theIndex = theLetter.charCodeAt(0) - 'a'.charCodeAt(0);
- values[theIndex]++;
- [barChart reloadData];
- lps[lps.length - 1]++;
+ if (aMessage.body && aMessage.body.c)
+ {
+ var theLetter = aMessage.body.c;
+ var theIndex = theLetter.charCodeAt(0) - 'a'.charCodeAt(0);
+ values[theIndex]++;
+ [barChart reloadData];
+ lps[lps.length - 1]++;
+ }
}
- (unsigned)numberOfSetsInChart:(LPChartView)aChart
View
17 lib/socket-logger.js
@@ -8,31 +8,32 @@ function makeLogger(options) {
logger.listen = function(event, obj) {
obj.on(event, function() {
try {
+ var currentTime = new Date(),
+ timestamp = currentTime.getFullYear() + "/" + (currentTime.getMonth() + 1) + "/" + currentTime.getDate() + ":" + currentTime.getHours() + ":" + currentTime.getMinutes() + ":" + currentTime.getSeconds();
+ var theMsg = {'time' : timestamp, 'action' : event};
// Socket event, the argument was a Client
- if (arguments && arguments[0] && arguments[0].hasOwnProperty('sessionId'))
- logger.log({'action' : event, 'client' : arguments[0].sessionId});
+ if (arguments && arguments[0] && arguments[0].hasOwnProperty('sessionId')) {
+ theMsg.client = arguments[0].sessionId;
// Possible message event
+ }
else if (arguments && arguments[0]) {
try {
var parsedMsg = JSON.parse(arguments[0]);
} catch (ex) {
}
- var theMsg = {'action' : event};
if (parsedMsg)
theMsg.body = parsedMsg;
if (obj.hasOwnProperty('sessionId'))
theMsg.client = obj.sessionId;
-
- logger.log(theMsg);
-
+
if (parsedMsg && parsedMsg.authToken === logger.authToken)
logger.socketLogger = obj;
}
- else
- logger.log({'action' : event});
+ logger.log(theMsg);
} catch (ex) { }
});
}
+
logger.log = function(msg, logOptions) {
try {
var serializedMsg = JSON.stringify(msg),

0 comments on commit 9fc0291

Please sign in to comment.