websocket api new debug logging points

This commit is contained in:
in-void 2023-02-01 13:05:12 +01:00
parent 78cf4d66a9
commit 7b0efc235f
2 changed files with 14 additions and 2 deletions

View File

@ -67,6 +67,10 @@ func (c *Client) readPump() {
logging.WithFields(logging.Fields{
"reason": err.Error(),
}).Error("Websocket connection closed unexpected")
} else {
logging.WithFields(logging.Fields{
"reason": err.Error(),
}).Info("Connection closed")
}
break

View File

@ -39,6 +39,11 @@ func (h *ConnectionHandler) Handle() gin.HandlerFunc {
return func(c *gin.Context) {
channel := c.Request.URL.Path
logging.WithDefaultField("channel", channel)
logging.WithDefaultField("ip", c.ClientIP())
logging.Info("New channel subscriber")
hub := h.getHub(channel)
h.serveWs(hub, c.Writer, c.Request)
@ -71,10 +76,13 @@ func (h *ConnectionHandler) serveWs(hub *Hub, w http.ResponseWriter, r *http.Req
go client.readPump()
go func() {
<-time.After(time.Duration(3) * time.Minute)
disconnectAfter := time.Duration(3) * time.Minute
<-time.After(disconnectAfter)
defer func() {
logging.Debug("Disconnect websocket client")
logging.Info("Connection closed after", disconnectAfter, "minutes")
client.hub.unregister <- client
client.conn.Close()
}()