frontend: improve log display
This commit is contained in:
parent
bdfdad2585
commit
ea04792c39
3 changed files with 39 additions and 6 deletions
|
@ -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{
|
||||
|
|
1
go.sum
1
go.sum
|
@ -71,6 +71,7 @@ golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8U
|
|||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
|
|
|
@ -63,15 +63,24 @@
|
|||
{{ end }}
|
||||
|
||||
<h2 id="region-log">Log</h2>
|
||||
<table class="table">
|
||||
<table class="table .table-sm">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td class="bg-dark text-white">
|
||||
{{ range $entry := .memory.Entries }}
|
||||
<code>{{ $entry }}</code><br />
|
||||
{{ end }}
|
||||
<tr class="bg-dark {{ levelToClasses $entry.Level }}">
|
||||
<td rowspan="2">
|
||||
{{ $entry.Timestamp.Format "2006-01-02 15:04:05 UTC"}}
|
||||
</td>
|
||||
<td>{{ $entry.Level }}</td>
|
||||
<td>
|
||||
<code class="{{ levelToClasses $entry.Level }}">{{ $entry.Message }}</code><br />
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="bg-dark {{ levelToClasses $entry.Level }}">
|
||||
<td colspan="2">
|
||||
<code class="{{ levelToClasses $entry.Level }}">{{ fieldsToJSON $entry.Fields }}</code><br />
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
|
|
Loading…
Reference in a new issue