feat: improve logging for client connects and disconnects

- add connection log to record client address on connect
- enhance disconnection log to include client address

🤖
This commit is contained in:
Sebastian Mark 2024-10-21 17:59:35 +02:00
parent f991ba885d
commit c6ce7d46ad
2 changed files with 3 additions and 1 deletions

View file

@ -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
}

View file

@ -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{