Better logging for unread counts.

This commit is contained in:
Samuel Clay 2013-05-01 12:51:59 -07:00
parent 9c9bbfb411
commit 7c83051c3d
4 changed files with 30 additions and 9 deletions

5
node/log.coffee Normal file
View file

@ -0,0 +1,5 @@
info = (username, message) ->
timestamp = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '')
console.log "[#{timestamp}] ---> [#{username}] #{message}"
exports.info = info

13
node/log.js Normal file
View file

@ -0,0 +1,13 @@
// Generated by CoffeeScript 1.4.0
(function() {
var info;
info = function(username, message) {
var timestamp;
timestamp = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
return console.log("[" + timestamp + "] ---> [" + username + "] " + message);
};
exports.info = info;
}).call(this);

View file

@ -1,5 +1,6 @@
fs = require 'fs'
redis = require 'redis'
log = require './log.js'
REDIS_SERVER = if process.env.NODE_ENV == 'development' then 'localhost' else 'db12'
SECURE = !!process.env.NODE_SSL
@ -39,9 +40,9 @@ io.configure 'development', ->
io.sockets.on 'connection', (socket) ->
socket.on 'subscribe:feeds', (@feeds, @username) ->
console.log " ---> [#{@username}] Subscribing to #{feeds.length} feeds " +
" (#{io.sockets.clients().length} users on) " +
" #{if SECURE then "(SSL)" else "(non-SSL)"}"
log.info @username, "Subscribing to #{feeds.length} feeds " +
" (#{io.sockets.clients().length} users on) " +
" #{if SECURE then "(SSL)" else "(non-SSL)"}"
if not @username
return
@ -52,7 +53,7 @@ io.sockets.on 'connection', (socket) ->
socket.subscribe.subscribe @username
socket.subscribe.on 'message', (channel, message) =>
console.log " ---> [#{@username}] Update on #{channel}: #{message}"
log.info @username, "Update on #{channel}: #{message}"
if channel == @username
socket.emit 'user:update', channel, message
else
@ -61,6 +62,6 @@ io.sockets.on 'connection', (socket) ->
socket.on 'disconnect', () ->
socket.subscribe?.end()
ip = socket.handshake.address.address
console.log " ---> [#{@username}] Disconnect (#{@feeds?.length} feeds, #{ip})," +
log.info @username, "Disconnect (#{@feeds?.length} feeds, #{ip})," +
" there are now #{io.sockets.clients().length-1} users. " +
" #{if SECURE then "(SSL)" else "(non-SSL)"}"

View file

@ -1,11 +1,13 @@
// Generated by CoffeeScript 1.4.0
(function() {
var REDIS_SERVER, SECURE, ca, certificate, fs, io, privateKey, redis;
var REDIS_SERVER, SECURE, ca, certificate, fs, io, log, privateKey, redis;
fs = require('fs');
redis = require('redis');
log = require('./log.js');
REDIS_SERVER = process.env.NODE_ENV === 'development' ? 'localhost' : 'db12';
SECURE = !!process.env.NODE_SSL;
@ -40,7 +42,7 @@
_this = this;
this.feeds = feeds;
this.username = username;
console.log((" ---> [" + this.username + "] Subscribing to " + feeds.length + " feeds ") + (" (" + (io.sockets.clients().length) + " users on) ") + (" " + (SECURE ? "(SSL)" : "(non-SSL)")));
log.info(this.username, ("Subscribing to " + feeds.length + " feeds ") + (" (" + (io.sockets.clients().length) + " users on) ") + (" " + (SECURE ? "(SSL)" : "(non-SSL)")));
if (!this.username) {
return;
}
@ -51,7 +53,7 @@
socket.subscribe.subscribe(this.feeds);
socket.subscribe.subscribe(this.username);
return socket.subscribe.on('message', function(channel, message) {
console.log(" ---> [" + _this.username + "] Update on " + channel + ": " + message);
log.info(_this.username, "Update on " + channel + ": " + message);
if (channel === _this.username) {
return socket.emit('user:update', channel, message);
} else {
@ -65,7 +67,7 @@
_ref.end();
}
ip = socket.handshake.address.address;
return console.log((" ---> [" + this.username + "] Disconnect (" + ((_ref1 = this.feeds) != null ? _ref1.length : void 0) + " feeds, " + ip + "),") + (" there are now " + (io.sockets.clients().length - 1) + " users. ") + (" " + (SECURE ? "(SSL)" : "(non-SSL)")));
return log.info(this.username, ("Disconnect (" + ((_ref1 = this.feeds) != null ? _ref1.length : void 0) + " feeds, " + ip + "),") + (" there are now " + (io.sockets.clients().length - 1) + " users. ") + (" " + (SECURE ? "(SSL)" : "(non-SSL)")));
});
});