Skip to content

Commit 90ec516

Browse files
author
Jack Anderson
committed
more server side logging, for science
1 parent 8541a19 commit 90ec516

File tree

5 files changed

+32
-3
lines changed

5 files changed

+32
-3
lines changed

app.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@ var app = express();
88
var server = http.createServer(app);
99
var io = require('socket.io').listen(server, {log: false});
1010
var lessCompiler = require('express-less-middleware')();
11+
var logger = require('./logger');
1112

1213
var rooms = {};
1314
var userCount = 0;
1415

16+
var logEvent = function(event, data) {
17+
logger.info({
18+
event: event,
19+
data: data
20+
}, 'socket event');
21+
};
22+
1523
/**
1624
* Method for passing events between host and clients
1725
* Use this method only when incoming event name matches
@@ -20,6 +28,7 @@ var userCount = 0;
2028
var setupRoomEvents = function(socket,room,events) {
2129
var emitFn = function(eventName) {
2230
return function(data) {
31+
logEvent(eventName, data);
2332
io.sockets.in(room).emit(eventName, data);
2433
};
2534
};
@@ -96,7 +105,7 @@ app.get(/^\/([0-9a-z]{1,5})$/, routes.invite);
96105

97106
// Listen on the port.
98107
server.listen(app.get('port'), function() {
99-
console.log('BitPoints is ready to go at http://localhost:' + config.port);
108+
logger.info('BitPoints is ready to go at http://localhost:' + config.port);
100109
});
101110

102111
// Socket stuff.
@@ -108,8 +117,8 @@ io.sockets.on('connection', function (socket) {
108117
var hostRoomId;
109118

110119
socket.on('createRoom', function (data) {
120+
logEvent('createRoom', data);
111121

112-
console.log('Room', data.roomId, 'created.');
113122
rooms[data.roomId] = data;
114123
socket.join(data.roomId);
115124
host = true;
@@ -123,6 +132,7 @@ io.sockets.on('connection', function (socket) {
123132
});
124133

125134
socket.on('joinRoom', function (data) {
135+
logEvent('joinRoom', data);
126136

127137
// Set client socket metadata.
128138
myName = data.name;

logger.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var bunyan = require('bunyan');
2+
3+
module.exports = bunyan.createLogger({
4+
name: 'bitpoints-logger',
5+
level: 'info'
6+
});
7+

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"dependencies": {
2121
"body-parser": "^1.15.0",
22+
"bunyan": "^1.8.9",
2223
"cookie-parser": "^1.4.1",
2324
"errorhandler": "^1.4.3",
2425
"express": "4.13.4",

public/javascripts/host.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ var getNumVotes = function() {
9797

9898
var processVotes = function() {
9999
voteData = {
100+
votes: votes,
100101
average: -1,
101102
trueAverage: -1,
102103
min: -1,
@@ -327,7 +328,11 @@ var page = new BP.Page({
327328
}
328329
}
329330

330-
socket.emit('roundEnd',{roomId: roomId, outcome: outcomeText});
331+
socket.emit('roundEnd',{
332+
roomId: roomId,
333+
roundData: voteData,
334+
outcome: outcomeText
335+
});
331336
},
332337

333338
toggleRound: function(e, $el){

public/javascripts/join.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ var page = new BP.Page({
4949

5050
socket: socket,
5151

52+
voting: false,
53+
5254
socketEvents: {
5355
'roomRefresh': 'joinRoom',
5456
'newRound': 'reset',
@@ -138,13 +140,15 @@ var page = new BP.Page({
138140
},
139141

140142
reset: function(data) {
143+
this.voting = true;
141144
this.$lastVote.removeClass('lastVote');
142145
if(data.ticket){ this.$ticketInfo.html(': <a href="'+data.ticket.url+'" target="_blank">'+data.ticket.key+'</a>'); }
143146
this.$status.hide().filter('.newRound').show();
144147
this.$estimateTable.removeClass('roundEnd').addClass('newRound');
145148
},
146149

147150
endRound: function(data) {
151+
this.voting = false;
148152
var text = 'Voting is closed.';
149153

150154
if (data.outcome) {
@@ -207,6 +211,8 @@ var page = new BP.Page({
207211
},
208212

209213
submitEstimate: function(e, $el) {
214+
if (!this.voting) { return; }
215+
210216
$('.lastVote').removeClass('lastVote');
211217

212218
var points = $el.addClass('lastVote').data('value'),

0 commit comments

Comments
 (0)