diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-03-16 14:59:44 -0400 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-03-16 11:59:44 -0700 |
commit | 0bc3e46082d9018188262f9cb8fdbc206d0656a0 (patch) | |
tree | 4ea3c374fff76fe12ad5f325987866baa69cea09 /app | |
parent | 24848f9d6a92eb1e09189c358636fd1ba32fa6d6 (diff) | |
download | chat-0bc3e46082d9018188262f9cb8fdbc206d0656a0.tar.gz chat-0bc3e46082d9018188262f9cb8fdbc206d0656a0.tar.bz2 chat-0bc3e46082d9018188262f9cb8fdbc206d0656a0.zip |
Implement GET /logs endpoint for APIv4 (#5778)
Diffstat (limited to 'app')
-rw-r--r-- | app/admin.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/app/admin.go b/app/admin.go index c551da50c..509d81840 100644 --- a/app/admin.go +++ b/app/admin.go @@ -18,14 +18,14 @@ import ( "github.com/mattermost/platform/utils" ) -func GetLogs() ([]string, *model.AppError) { - lines, err := GetLogsSkipSend() +func GetLogs(page, perPage int) ([]string, *model.AppError) { + lines, err := GetLogsSkipSend(page, perPage) if err != nil { return nil, err } if einterfaces.GetClusterInterface() != nil { - clines, err := einterfaces.GetClusterInterface().GetLogs() + clines, err := einterfaces.GetClusterInterface().GetLogs(page, perPage) if err != nil { return nil, err } @@ -36,7 +36,7 @@ func GetLogs() ([]string, *model.AppError) { return lines, nil } -func GetLogsSkipSend() ([]string, *model.AppError) { +func GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) { var lines []string if utils.Cfg.LogSettings.EnableFile { @@ -47,9 +47,20 @@ func GetLogsSkipSend() ([]string, *model.AppError) { defer file.Close() + offsetCount := 0 + limitCount := 0 scanner := bufio.NewScanner(file) for scanner.Scan() { - lines = append(lines, scanner.Text()) + if limitCount >= perPage { + break + } + + if offsetCount >= page*perPage { + lines = append(lines, scanner.Text()) + limitCount++ + } else { + offsetCount++ + } } } else { lines = append(lines, "") |