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:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user