frontend: improve log display

This commit is contained in:
Florian Klink 2019-12-04 15:21:17 +01:00
parent bdfdad2585
commit ea04792c39
3 changed files with 39 additions and 6 deletions

View file

@ -4,12 +4,15 @@ import (
"fmt"
"io/ioutil"
"net/http"
"encoding/json"
"html/template"
"github.com/gin-gonic/gin"
"github.com/rakyll/statik/fs"
"github.com/apex/log"
"github.com/tweag/gerrit-queue/gerrit"
"github.com/tweag/gerrit-queue/misc"
_ "github.com/tweag/gerrit-queue/statik" // register static assets
@ -68,6 +71,26 @@ func MakeFrontend(rotatingLogHandler *misc.RotatingLogHandler, gerritClient *ger
"changesetURL": func(changeset *gerrit.Changeset) string {
return gerritClient.GetChangesetURL(changeset)
},
"levelToClasses": func(level log.Level) string {
switch level {
case log.DebugLevel:
return "text-muted"
case log.InfoLevel:
return "text-info"
case log.WarnLevel:
return "text-warning"
case log.ErrorLevel:
return "text-danger"
case log.FatalLevel:
return "text-danger"
default:
return "text-white"
}
},
"fieldsToJSON": func(fields log.Fields) string {
jsonData, _ := json.Marshal(fields)
return string(jsonData)
},
}
tmpl := template.Must(loadTemplate([]string{