From bca2cfda13ee3139001a132872fc3806a97d073c Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 7 Jul 2022 17:25:52 -0500 Subject: [PATCH] Update:Remove log listener for root user & only set when on logger config page --- client/pages/config/log.vue | 1 + server/Server.js | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/client/pages/config/log.vue b/client/pages/config/log.vue index 50ccc3e9..f621b9f2 100644 --- a/client/pages/config/log.vue +++ b/client/pages/config/log.vue @@ -161,6 +161,7 @@ export default { }, beforeDestroy() { if (!this.$root.socket) return + this.$root.socket.emit('remove_log_listener') this.$root.socket.off('daily_logs', this.dailyLogsLoaded) this.$root.socket.off('log', this.logEvtReceived) } diff --git a/server/Server.js b/server/Server.js index c2895de9..0d75eaea 100644 --- a/server/Server.js +++ b/server/Server.js @@ -278,6 +278,7 @@ class Server { // Logs socket.on('set_log_listener', (level) => Logger.addSocketListener(socket, level)) + socket.on('remove_log_listener', () => Logger.removeSocketListener(socket.id)) socket.on('fetch_daily_logs', () => this.logManager.socketRequestDailyLogs(socket)) socket.on('ping', () => { @@ -287,21 +288,21 @@ class Server { socket.emit('pong') }) - socket.on('disconnect', () => { + socket.on('disconnect', (reason) => { Logger.removeSocketListener(socket.id) var _client = this.clients[socket.id] if (!_client) { - Logger.warn('[Server] Socket disconnect, no client ' + socket.id) + Logger.warn(`[Server] Socket ${socket.id} disconnect, no client (Reason: ${reason})`) } else if (!_client.user) { - Logger.info('[Server] Unauth socket disconnected ' + socket.id) + Logger.info(`[Server] Unauth socket ${socket.id} disconnected (Reason: ${reason})`) delete this.clients[socket.id] } else { Logger.debug('[Server] User Offline ' + _client.user.username) this.io.emit('user_offline', _client.user.toJSONForPublic(this.playbackSessionManager.sessions, this.db.libraryItems)) const disconnectTime = Date.now() - _client.connected_at - Logger.info(`[Server] Socket ${socket.id} disconnected from client "${_client.user.username}" after ${disconnectTime}ms`) + Logger.info(`[Server] Socket ${socket.id} disconnected from client "${_client.user.username}" after ${disconnectTime}ms (Reason: ${reason})`) delete this.clients[socket.id] } }) @@ -471,11 +472,6 @@ class Server { initialPayload.usersOnline = this.usersOnline } client.socket.emit('init', initialPayload) - - // Setup log listener for root user - if (user.type === 'root') { - Logger.addSocketListener(socket, this.db.serverSettings.logLevel || 0) - } } async stop() {