Skip to content

Commit 42c8fa0

Browse files
committed
Merge pull request #1236 from DaftMonk/feature/improve-socketio-logging
feat(app): improved socket.io logging
2 parents fa4c6bc + c1fd93f commit 42c8fa0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Diff for: app/templates/server/config/socketio(socketio).js

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function onDisconnect(socket) {
1414
function onConnect(socket) {
1515
// When the client emits 'info', this listens and executes
1616
socket.on('info', function(data) {
17-
console.info('[%s] %s', socket.address, JSON.stringify(data, null, 2));
17+
socket.log(JSON.stringify(data, null, 2));
1818
});
1919

2020
// Insert sockets below
@@ -43,14 +43,18 @@ module.exports = function(socketio) {
4343

4444
socket.connectedAt = new Date();
4545

46+
socket.log = function(...data) {
47+
console.log(`SocketIO ${socket.nsp.name} [${socket.address}]`, ...data);
48+
};
49+
4650
// Call onDisconnect.
4751
socket.on('disconnect', function() {
4852
onDisconnect(socket);
49-
console.info('[%s] DISCONNECTED', socket.address);
53+
socket.log('DISCONNECTED');
5054
});
5155

5256
// Call onConnect.
5357
onConnect(socket);
54-
console.info('[%s] CONNECTED', socket.address);
58+
socket.log('CONNECTED');
5559
});
5660
};

0 commit comments

Comments
 (0)