From 13d7cd09196853820fc3701ce449cbe45258c752 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Thu, 24 Oct 2024 22:48:45 +0200 Subject: [PATCH] feat: add number of connected clients to log output --- internal/websocket/client_commands.go | 2 +- internal/websocket/handle_connections.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index 67a917d..d394601 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -16,7 +16,7 @@ func handleClientCommands(ws *websocket.Conn) { _, message, err := ws.ReadMessage() if err != nil { - log.Printf("Client disconnected from %s (%v)", ws.NetConn().RemoteAddr(), err) + log.Printf("Client disconnected from %s (%v) (total: %d)", ws.NetConn().RemoteAddr(), err, len(Clients)-1) delete(Clients, ws) break } diff --git a/internal/websocket/handle_connections.go b/internal/websocket/handle_connections.go index c80605a..47c1e9a 100644 --- a/internal/websocket/handle_connections.go +++ b/internal/websocket/handle_connections.go @@ -27,7 +27,7 @@ func HandleConnections(w http.ResponseWriter, r *http.Request) { } defer ws.Close() - log.Printf("Client connected from %v", ws.NetConn().RemoteAddr()) + log.Printf("Client connected from %v (total: %d)", ws.NetConn().RemoteAddr(), len(Clients)+1) // Register the new client mu.Lock()