Skip to content

Commit 1dc7dc9

Browse files
authored
Merge pull request #30 from websdotcom/more-logging
more server side logging, for science
2 parents 8541a19 + 0bbfe0a commit 1dc7dc9

7 files changed

Lines changed: 57 additions & 15 deletions

File tree

app.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,22 @@ 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 loggableEvents = [
17+
'newVote','newRound','roundEnd','kickVoter','updateVoters'
18+
];
19+
20+
var logEvent = function(event, data) {
21+
logger.info({
22+
event: event,
23+
data: data
24+
}, 'socket event');
25+
};
26+
1527
/**
1628
* Method for passing events between host and clients
1729
* Use this method only when incoming event name matches
@@ -20,6 +32,9 @@ var userCount = 0;
2032
var setupRoomEvents = function(socket,room,events) {
2133
var emitFn = function(eventName) {
2234
return function(data) {
35+
if (_.includes(loggableEvents, eventName)) {
36+
logEvent(eventName, data);
37+
}
2338
io.sockets.in(room).emit(eventName, data);
2439
};
2540
};
@@ -96,7 +111,7 @@ app.get(/^\/([0-9a-z]{1,5})$/, routes.invite);
96111

97112
// Listen on the port.
98113
server.listen(app.get('port'), function() {
99-
console.log('BitPoints is ready to go at http://localhost:' + config.port);
114+
logger.info('BitPoints is ready to go at http://localhost:' + config.port);
100115
});
101116

102117
// Socket stuff.
@@ -108,8 +123,8 @@ io.sockets.on('connection', function (socket) {
108123
var hostRoomId;
109124

110125
socket.on('createRoom', function (data) {
126+
logEvent('createRoom', data);
111127

112-
console.log('Room', data.roomId, 'created.');
113128
rooms[data.roomId] = data;
114129
socket.join(data.roomId);
115130
host = true;
@@ -123,6 +138,7 @@ io.sockets.on('connection', function (socket) {
123138
});
124139

125140
socket.on('joinRoom', function (data) {
141+
logEvent('joinRoom', data);
126142

127143
// Set client socket metadata.
128144
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'),

public/stylesheets/style.less

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ html {
125125
padding-top: 80px;
126126
}
127127

128+
#voterRoomInfo {
129+
padding: 5px 10px;
130+
131+
.voterImageSmall {
132+
width: 20px;
133+
height: 20px;
134+
margin: 0 0 0 5px;
135+
}
136+
}
137+
128138
table#estimateOptions {
129139
td {
130140
font-size: 2em;

public/stylesheets/voterRoom.less

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,21 @@
33
*/
44
#voterRoomInfo {
55
display: block;
6-
height: 60px;
7-
padding: 0 20px;
6+
padding: 10px 20px;
87
background: rgba(0,0,0,0.5);
9-
line-height: 60px;
108
font-size: 14px;
119
font-weight: bold;
1210

13-
#voterList {
14-
float: right;
15-
16-
.avatars {
17-
float: right;
18-
}
11+
#voterList .avatars {
12+
display: inline-block;
13+
vertical-align: middle;
1914
}
2015

2116
.voterImageSmall {
2217
float: left;
2318
height: 30px;
2419
width: 30px;
25-
margin: 15px 5px;
20+
margin: 0 0 0 5px;
2621
}
2722
}
2823

@@ -33,21 +28,23 @@
3328

3429
.status {
3530
display: none;
36-
width: 100%;
3731
height: 20px;
3832
padding: 10px;
3933
margin: 10px 0;
4034
border-radius: 6px;
4135
line-height: 20px;
4236
background: rgba(0,0,0,0.5);
43-
color: white;
37+
color: @text;
38+
font-size: 14px;
39+
font-weight: bold;
4440

4541
&.roundEnd {
4642
display: block;
4743
}
4844

4945
&.newRound {
5046
background: @accentColor;
47+
color: white;
5148
}
5249
}
5350

0 commit comments

Comments
 (0)