mirror of
https://github.com/owncast/owncast.git
synced 2024-11-22 12:49:37 +03:00
85e7af3d5f
* chore(go): update go version to 1.20. Closes #2185 * chore(go): run better align against project To optimize struct field order. Closes #2870 * chore(go): update CI jobs to use Go 1.20 * fix(go): linter warnings for Go 1.20 update
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package admin
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/owncast/owncast/logging"
|
|
"github.com/sirupsen/logrus"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// GetLogs will return all logs.
|
|
func GetLogs(w http.ResponseWriter, r *http.Request) {
|
|
logs := logging.Logger.AllEntries()
|
|
response := make([]logsResponse, 0)
|
|
|
|
for i := 0; i < len(logs); i++ {
|
|
response = append(response, fromEntry(logs[i]))
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
if err := json.NewEncoder(w).Encode(response); err != nil {
|
|
log.Errorln(err)
|
|
}
|
|
}
|
|
|
|
// GetWarnings will return only warning and error logs.
|
|
func GetWarnings(w http.ResponseWriter, r *http.Request) {
|
|
logs := logging.Logger.WarningEntries()
|
|
response := make([]logsResponse, 0)
|
|
|
|
for i := 0; i < len(logs); i++ {
|
|
logEntry := logs[i]
|
|
if logEntry != nil {
|
|
response = append(response, fromEntry(logEntry))
|
|
}
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
if err := json.NewEncoder(w).Encode(response); err != nil {
|
|
log.Errorln(err)
|
|
}
|
|
}
|
|
|
|
type logsResponse struct {
|
|
Time time.Time `json:"time"`
|
|
Message string `json:"message"`
|
|
Level string `json:"level"`
|
|
}
|
|
|
|
func fromEntry(e *logrus.Entry) logsResponse {
|
|
return logsResponse{
|
|
Message: e.Message,
|
|
Level: e.Level.String(),
|
|
Time: e.Time,
|
|
}
|
|
}
|