Admin log table (#21153)
* Reformat Log Output for SysAdmin UI * Restore old code * Update * Backend first pass * PR feedback * Set helpers to private * Lint fix * Fix mocks * Fix another mock * Fix lint again * Fix i18n * Update app/admin.go Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> * PR feedback * FIx lint issue --------- Co-authored-by: Daniel Schalla <daniel@schalla.me> Co-authored-by: Nevyana Angelova <nevyangelova@Nevyanas-MacBook-Pro.local> Co-authored-by: Devin Binnie <devin.binnie@mattermost.com> Co-authored-by: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
@@ -134,13 +134,16 @@ func (c *ClusterMock) StartInterNodeCommunication() {}
|
||||
func (c *ClusterMock) StopInterNodeCommunication() {}
|
||||
func (c *ClusterMock) RegisterClusterMessageHandler(event model.ClusterEvent, crm einterfaces.ClusterMessageHandler) {
|
||||
}
|
||||
func (c *ClusterMock) GetClusterId() string { return "cluster_mock" }
|
||||
func (c *ClusterMock) IsLeader() bool { return false }
|
||||
func (c *ClusterMock) GetMyClusterInfo() *model.ClusterInfo { return nil }
|
||||
func (c *ClusterMock) GetClusterInfos() []*model.ClusterInfo { return nil }
|
||||
func (c *ClusterMock) NotifyMsg(buf []byte) {}
|
||||
func (c *ClusterMock) GetClusterStats() ([]*model.ClusterStats, *model.AppError) { return nil, nil }
|
||||
func (c *ClusterMock) GetLogs(page, perPage int) ([]string, *model.AppError) { return nil, nil }
|
||||
func (c *ClusterMock) GetClusterId() string { return "cluster_mock" }
|
||||
func (c *ClusterMock) IsLeader() bool { return false }
|
||||
func (c *ClusterMock) GetMyClusterInfo() *model.ClusterInfo { return nil }
|
||||
func (c *ClusterMock) GetClusterInfos() []*model.ClusterInfo { return nil }
|
||||
func (c *ClusterMock) NotifyMsg(buf []byte) {}
|
||||
func (c *ClusterMock) GetClusterStats() ([]*model.ClusterStats, *model.AppError) { return nil, nil }
|
||||
func (c *ClusterMock) GetLogs(page, perPage int) ([]string, *model.AppError) { return nil, nil }
|
||||
func (c *ClusterMock) QueryLogs(page, perPage int) (map[string][]string, *model.AppError) {
|
||||
return nil, nil
|
||||
}
|
||||
func (c *ClusterMock) GetPluginStatuses() (model.PluginStatuses, *model.AppError) { return nil, nil }
|
||||
func (c *ClusterMock) ConfigChanged(previousConfig *model.Config, newConfig *model.Config, sendToOtherServer bool) *model.AppError {
|
||||
return nil
|
||||
|
||||
@@ -5,6 +5,7 @@ package platform
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -123,7 +124,7 @@ func (ps *PlatformService) RemoveUnlicensedLogTargets(license *model.License) {
|
||||
})
|
||||
}
|
||||
|
||||
func (ps *PlatformService) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) {
|
||||
func (ps *PlatformService) GetLogsSkipSend(page, perPage int, logFilter *model.LogFilter) ([]string, *model.AppError) {
|
||||
var lines []string
|
||||
|
||||
if *ps.Config().LogSettings.EnableFile {
|
||||
@@ -172,7 +173,22 @@ func (ps *PlatformService) GetLogsSkipSend(page, perPage int) ([]string, *model.
|
||||
if err != nil {
|
||||
return nil, model.NewAppError("getLogs", "api.admin.file_read_error", nil, "", http.StatusInternalServerError).Wrap(err)
|
||||
}
|
||||
lines = append(lines, string(line))
|
||||
|
||||
filtered := false
|
||||
var entry *model.LogEntry
|
||||
err = json.Unmarshal(line, &entry)
|
||||
if err != nil {
|
||||
mlog.Debug("Failed to parse line, skipping")
|
||||
} else {
|
||||
filtered = isLogFilteredByLevel(logFilter, entry) || filtered
|
||||
filtered = isLogFilteredByDate(logFilter, entry) || filtered
|
||||
}
|
||||
|
||||
if filtered {
|
||||
lineCount--
|
||||
} else {
|
||||
lines = append(lines, string(line))
|
||||
}
|
||||
}
|
||||
if pos == 0 {
|
||||
break
|
||||
@@ -194,3 +210,48 @@ func (ps *PlatformService) GetLogsSkipSend(page, perPage int) ([]string, *model.
|
||||
|
||||
return lines, nil
|
||||
}
|
||||
|
||||
func isLogFilteredByLevel(logFilter *model.LogFilter, entry *model.LogEntry) bool {
|
||||
logLevels := logFilter.LogLevels
|
||||
if len(logLevels) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, level := range logLevels {
|
||||
if entry.Level == level {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func isLogFilteredByDate(logFilter *model.LogFilter, entry *model.LogEntry) bool {
|
||||
if logFilter.DateFrom == "" && logFilter.DateTo == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
dateFrom, err := time.Parse("2006-01-02 15:04:05.999 -07:00", logFilter.DateFrom)
|
||||
if err != nil {
|
||||
dateFrom = time.Time{}
|
||||
}
|
||||
dateTo, err := time.Parse("2006-01-02 15:04:05.999 -07:00", logFilter.DateTo)
|
||||
if err != nil {
|
||||
dateTo = time.Now()
|
||||
}
|
||||
|
||||
timestamp, err := time.Parse("2006-01-02 15:04:05.999 -07:00", entry.Timestamp)
|
||||
if err != nil {
|
||||
mlog.Debug("Cannot parse timestamp, skipping")
|
||||
return false
|
||||
}
|
||||
|
||||
if timestamp.Equal(dateFrom) || timestamp.Equal(dateTo) {
|
||||
return false
|
||||
}
|
||||
if timestamp.After(dateFrom) && timestamp.Before(dateTo) {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user