From 15d9322a31c1e13616bf6469d6aec48aa3db4f2d Mon Sep 17 00:00:00 2001 From: Alexander Emelin Date: Sat, 21 Oct 2023 09:14:24 +0300 Subject: [PATCH] emulation logging tweaks --- emulation.go | 6 ++++-- handler_http_stream.go | 2 +- handler_sse.go | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/emulation.go b/emulation.go index b14bb64e..ddb6c1d3 100644 --- a/emulation.go +++ b/emulation.go @@ -53,11 +53,11 @@ func (s *EmulationHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { data, err := io.ReadAll(r.Body) if err != nil { + s.node.logger.log(newLogEntry(LogLevelInfo, "error reading emulation request body", map[string]any{"error": err.Error()})) if len(data) >= maxBytesSize { rw.WriteHeader(http.StatusRequestEntityTooLarge) return } - s.node.logger.log(newLogEntry(LogLevelError, "can't read emulation request body", map[string]any{"error": err.Error()})) rw.WriteHeader(http.StatusInternalServerError) return } @@ -69,7 +69,9 @@ func (s *EmulationHandler) ServeHTTP(rw http.ResponseWriter, r *http.Request) { err = json.Unmarshal(data, &req) } if err != nil { - s.node.logger.log(newLogEntry(LogLevelInfo, "can't unmarshal emulation request", map[string]any{"req": &req, "error": err.Error()})) + if s.node.LogEnabled(LogLevelInfo) { + s.node.logger.log(newLogEntry(LogLevelInfo, "can't unmarshal emulation request", map[string]any{"error": err.Error(), "data": string(data)})) + } rw.WriteHeader(http.StatusBadRequest) return } diff --git a/handler_http_stream.go b/handler_http_stream.go index ffb7bb53..a6fda948 100644 --- a/handler_http_stream.go +++ b/handler_http_stream.go @@ -61,7 +61,7 @@ func (h *HTTPStreamHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { var err error requestData, err = io.ReadAll(r.Body) if err != nil { - h.node.Log(NewLogEntry(LogLevelError, "error reading body", map[string]any{"error": err.Error()})) + h.node.Log(NewLogEntry(LogLevelInfo, "error reading http stream request body", map[string]any{"error": err.Error()})) if len(requestData) >= maxBytesSize { w.WriteHeader(http.StatusRequestEntityTooLarge) return diff --git a/handler_sse.go b/handler_sse.go index 506ad9a3..4ddf88e5 100644 --- a/handler_sse.go +++ b/handler_sse.go @@ -61,11 +61,11 @@ func (h *SSEHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { var err error requestData, err = io.ReadAll(r.Body) if err != nil { + h.node.Log(NewLogEntry(LogLevelInfo, "error reading sse request body", map[string]any{"error": err.Error()})) if len(requestData) >= maxBytesSize { w.WriteHeader(http.StatusRequestEntityTooLarge) return } - h.node.Log(NewLogEntry(LogLevelError, "error reading body", map[string]any{"error": err.Error()})) w.WriteHeader(http.StatusInternalServerError) return }