refactor: add client log on task list change

This commit is contained in:
Jordan Knott
2021-10-25 21:03:22 -05:00
parent cf63783174
commit ef2aadefbb
7 changed files with 63 additions and 3 deletions

33
internal/route/log.go Normal file
View File

@ -0,0 +1,33 @@
package route
import (
"encoding/json"
"net/http"
log "github.com/sirupsen/logrus"
)
type ClientLog struct {
Level string `json:"level"`
Message string `json:"message"`
Logger string `json:"logger"`
Stacktrace string `json:"stacktrace"`
Timestamp string `json:"timestamp"`
}
type ClientLogs struct {
Logs []ClientLog `json:"logs"`
}
func (h *TaskcafeHandler) HandleClientLog(w http.ResponseWriter, r *http.Request) {
var clientLogs ClientLogs
err := json.NewDecoder(r.Body).Decode(&clientLogs)
if err != nil {
w.WriteHeader(http.StatusBadRequest)
log.Debug("bad request body")
return
}
for _, logEntry := range clientLogs.Logs {
log.WithField("level", logEntry.Level).WithField("message", logEntry.Message).Info("found log")
}
}

View File

@ -103,6 +103,7 @@ func NewRouter(dbConnection *sqlx.DB, emailConfig utils.EmailConfig, securityCon
mux.Post("/auth/confirm", taskcafeHandler.ConfirmUser)
mux.Post("/auth/register", taskcafeHandler.RegisterUser)
mux.Get("/settings", taskcafeHandler.PublicSettings)
mux.Post("/logger", taskcafeHandler.HandleClientLog)
})
auth := AuthenticationMiddleware{*repository}
r.Group(func(mux chi.Router) {