comment out console.log to reduce output logs

This commit is contained in:
Luk 2024-02-16 09:59:23 +08:00
parent 00702c4aea
commit b37fdb40a2

View File

@ -10,10 +10,10 @@ const my = {
module.exports = {
initSocket (webServer) {
my.wsServer = new ws.Server({ server: webServer })
console.info({ _at: new Date().toJSON(), _from: 'Socket:initSocket', _type: 'CLOG', about: 'Base Socket Server is initialized.' }, '\n,')
//console.info({ _at: new Date().toJSON(), _from: 'Socket:initSocket', _type: 'CLOG', about: 'Base Socket Server is initialized.' }, '\n,')
my.wsServer.on('connection', (socket, req) => {
//console.info({_at:new Date().toJSON(), _from: 'Socket:onConnection', _type:'CLOG', about: `A socket is connecting from ${req.connection.remoteAddress}:${req.connection.remotePort}.`},'\n,')
//console.info({_at:new Date().toJSON(), _from: 'basesocket:onConnection', _type:'CLOG', about: `A socket is connecting from ${req.connection.remoteAddress}:${req.connection.remotePort}.`},'\n,')
// socket.isAlive = true
// socket.on('pong', function() { this.isAlive = true })
@ -26,9 +26,9 @@ module.exports = {
if (dataObj?.skevent === 'PING') {
return
}
console.log({ _at: new Date().toJSON(), _from: 'Socket:onMessage', _type: 'CLOG', usid: socket.usid, dataObj }, '\n,')
//console.log({ _at: new Date().toJSON(), _from: 'basesocket:onMessage', _type: 'CLOG', usid: socket.usid, skevent: dataObj?.skevent }, '\n,')
} catch (exception) {
console.error({ _at: new Date().toJSON(), _from: 'Socket:onMessage', _type: 'CERROR', about: 'Unable to parse socket message', data }, '\n,')
console.error({ _at: new Date().toJSON(), _from: 'basesocket:onMessage', _type: 'CERROR', about: 'Unable to parse socket message', data }, '\n,')
return
}
if (['SOCKET_OWNER', 'SOCKET_OWNER_RECONNECT'].includes(dataObj.skevent)) {
@ -37,13 +37,13 @@ module.exports = {
if (typeof dataObj._passtokenSource?.usid === 'string') {
my.socketPool[dataObj._passtokenSource.usid] = socket
socket.usid = dataObj._passtokenSource.usid
console.log({
_at: new Date().toJSON(), _from: 'Socket:onMessage', _type: 'CLOG',
skevent: dataObj.skevent,
usid: dataObj._passtokenSource.usid,
socketPool: Object.keys(my.socketPool)?.length,
socketClients: my.wsServer.clients.size
}, '\n,')
// console.log({
// _at: new Date().toJSON(), _from: 'basesocket:onMessage', _type: 'CLOG',
// skevent: dataObj.skevent,
// usid: dataObj._passtokenSource.usid,
// socketPool: Object.keys(my.socketPool)?.length,
// socketClients: my.wsServer.clients.size
// }, '\n,')
}
}
@ -62,7 +62,7 @@ module.exports = {
// }, 60000)
socket.on('close', () => {
//console.log({_at:new Date().toJSON(), _from: 'Socket:onClose', _type:'CLOG', usid: socket?.usid},'\n,') // don't know why, but this output happens too often without usid.
//console.log({_at:new Date().toJSON(), _from: 'basesocket:onClose', _type:'CLOG', usid: socket?.usid},'\n,') // don't know why, but this output happens too often without usid.
delete my.socketPool[socket?.usid]
// clearInterval(heartbeat)
})