refactor: add client log on task list change
This commit is contained in:
33
internal/route/log.go
Normal file
33
internal/route/log.go
Normal 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")
|
||||
}
|
||||
}
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user