Skip to content

Commit

Permalink
feat: improve websocket connection logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kalinkrustev committed Feb 26, 2025
1 parent d1e10be commit 4cd2a05
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mono-log/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const init = async () => {
const wss = new WebSocketServer({ server: server.listener });

function heartbeat() {
console.log(`WebSocket heartbeat: ${this?._socket?.remoteAddress}:${this?._socket?.remotePort}`);
this.isAlive = true;
}

Expand All @@ -46,8 +45,9 @@ const init = async () => {
ws.on('error', console.error);
ws.on('pong', heartbeat);
ws.on('close', function wsClose(code, reason) {
console.log(`WebSocket ${ws?._socket?.remoteAddress}:${ws?._socket?.remotePort} closed`, code, reason);
console.log(`WebSocket closed: ${ws?._socket?.remoteAddress}:${ws?._socket?.remotePort}, code:${code}, reason: ${reason}`);
});
console.log(`WebSocket connected: ${ws?._socket?.remoteAddress}:${ws?._socket?.remotePort}`);
});

const interval = setInterval(function ping() {
Expand Down

0 comments on commit 4cd2a05

Please sign in to comment.