Skip to content

Commit

Permalink
log connection duration as string
Browse files Browse the repository at this point in the history
  • Loading branch information
FZambia committed Oct 5, 2024
1 parent cb46d6b commit b2efced
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion _examples/custom_ws_nhooyr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (s *customWebsocketHandler) ServeHTTP(rw http.ResponseWriter, r *http.Reque
defer func() { _ = closeFn() }()
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelDebug, "client connection established", map[string]any{"client": c.ID(), "transport": websocketTransportName}))
defer func(started time.Time) {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelDebug, "client connection completed", map[string]any{"client": c.ID(), "transport": websocketTransportName, "duration": time.Since(started)}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelDebug, "client connection completed", map[string]any{"client": c.ID(), "transport": websocketTransportName, "duration": time.Since(started).String()}))
}(time.Now())

for {
Expand Down
2 changes: 1 addition & 1 deletion _examples/unidirectional_ws/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ func (s *WebsocketHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {

s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelDebug, "client connection established", map[string]any{"client": c.ID(), "transport": transport.Name()}))
defer func(started time.Time) {
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelDebug, "client connection completed", map[string]any{"client": c.ID(), "transport": transport.Name(), "duration": time.Since(started)}))
s.node.Log(centrifuge.NewLogEntry(centrifuge.LogLevelDebug, "client connection completed", map[string]any{"client": c.ID(), "transport": transport.Name(), "duration": time.Since(started).String()}))
}(time.Now())

_, data, err := conn.ReadMessage()
Expand Down
2 changes: 1 addition & 1 deletion handler_http_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (h *HTTPStreamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if h.node.LogEnabled(LogLevelDebug) {
h.node.Log(NewLogEntry(LogLevelDebug, "client connection established", map[string]any{"transport": transport.Name(), "client": c.ID()}))
defer func(started time.Time) {
h.node.Log(NewLogEntry(LogLevelDebug, "client connection completed", map[string]any{"duration": time.Since(started), "transport": transport.Name(), "client": c.ID()}))
h.node.Log(NewLogEntry(LogLevelDebug, "client connection completed", map[string]any{"duration": time.Since(started).String(), "transport": transport.Name(), "client": c.ID()}))
}(time.Now())
}

Expand Down
2 changes: 1 addition & 1 deletion handler_sse.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (h *SSEHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if h.node.LogEnabled(LogLevelDebug) {
h.node.Log(NewLogEntry(LogLevelDebug, "client connection established", map[string]any{"transport": transport.Name(), "client": c.ID()}))
defer func(started time.Time) {
h.node.Log(NewLogEntry(LogLevelDebug, "client connection completed", map[string]any{"duration": time.Since(started), "transport": transport.Name(), "client": c.ID()}))
h.node.Log(NewLogEntry(LogLevelDebug, "client connection completed", map[string]any{"duration": time.Since(started).String(), "transport": transport.Name(), "client": c.ID()}))
}(time.Now())
}

Expand Down
2 changes: 1 addition & 1 deletion handler_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (s *WebsocketHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
if s.node.LogEnabled(LogLevelDebug) {
s.node.logger.log(newLogEntry(LogLevelDebug, "client connection established", map[string]any{"client": c.ID(), "transport": transportWebsocket}))
defer func(started time.Time) {
s.node.logger.log(newLogEntry(LogLevelDebug, "client connection completed", map[string]any{"client": c.ID(), "transport": transportWebsocket, "duration": time.Since(started)}))
s.node.logger.log(newLogEntry(LogLevelDebug, "client connection completed", map[string]any{"client": c.ID(), "transport": transportWebsocket, "duration": time.Since(started).String()}))
}(time.Now())
}

Expand Down

0 comments on commit b2efced

Please sign in to comment.