From c6ce7d46ade59a94f8c9e4e3dc4e7b4ccb40e41e Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Mon, 21 Oct 2024 17:59:35 +0200 Subject: [PATCH] feat: improve logging for client connects and disconnects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add connection log to record client address on connect - enhance disconnection log to include client address 🤖 --- internal/websocket/client_commands.go | 2 +- internal/websocket/handle_connections.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index d46f451..c53f45b 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -18,7 +18,7 @@ func handleClientCommands(ws *websocket.Conn) { _, message, err := ws.ReadMessage() if err != nil { - log.Printf("Client disconnected: %v", err) + log.Printf("Client disconnected from %s (%v)", ws.NetConn().RemoteAddr(), err) delete(Clients, ws) break } diff --git a/internal/websocket/handle_connections.go b/internal/websocket/handle_connections.go index be49918..c80605a 100644 --- a/internal/websocket/handle_connections.go +++ b/internal/websocket/handle_connections.go @@ -27,6 +27,8 @@ func HandleConnections(w http.ResponseWriter, r *http.Request) { } defer ws.Close() + log.Printf("Client connected from %v", ws.NetConn().RemoteAddr()) + // Register the new client mu.Lock() Clients[ws] = &models.Client{