feat: add /server/log/{prefix} endpoint

/{prefix} is optional

Sample usage: kapow set /server/log/myapp "$msg"

Co-authored-by: Roberto Abdelkader Martínez Pérez <robertomartinezp@gmail.com>
This commit is contained in:
pancho horrillo
2020-12-18 11:48:25 +01:00
parent cb6873e559
commit 7c4e32a34b
2 changed files with 19 additions and 0 deletions
+15
View File
@@ -23,6 +23,7 @@ import (
"net/textproto"
"strconv"
"github.com/BBVA/kapow/internal/logger"
"github.com/BBVA/kapow/internal/server/httperror"
"github.com/BBVA/kapow/internal/server/model"
"github.com/gorilla/mux"
@@ -231,3 +232,17 @@ func setResponseBody(w http.ResponseWriter, r *http.Request, h *model.Handler) {
}
h.SentBytes += n
}
func setServerLog(w http.ResponseWriter, r *http.Request, h *model.Handler) {
msg, err := ioutil.ReadAll(r.Body)
if err != nil {
httperror.ErrorJSON(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
handlerId := mux.Vars(r)["handlerID"]
if prefix := mux.Vars(r)["prefix"]; prefix == "" {
logger.L.Printf("%s %s\n", handlerId, msg)
} else {
logger.L.Printf("%s %s: %s\n", handlerId, prefix, msg)
}
}